Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some compilation errors #1162

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 76 additions & 74 deletions include/retdec/capstone2llvmir/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,55 @@ namespace capstone2llvmir {
* Base class for all Capstone2LllvmIr errors.
* This class itself should never be thrown.
*/
class BaseError : public std::exception
{
public:
virtual ~BaseError() = default;
class BaseError : public std::exception {
public:
virtual ~BaseError() = default;
};

/**
* An exception class encapsulating all Capstone errors.
*/
class CapstoneError : public BaseError
{
public:
CapstoneError(cs_err e);
class CapstoneError : public BaseError {
public:
CapstoneError(cs_err e);

std::string getMessage() const;
virtual const char* what() const noexcept override;
std::string getMessage() const;
virtual const char* what() const noexcept override;

private:
/// Capstone error.
cs_err _csError = CS_ERR_OK;
private:
/// Capstone error.
cs_err _csError = CS_ERR_OK;
};

/**
* An exception class related to Capstone mode setting errors.
*/
class ModeSettingError : public BaseError
{
public:
enum class eType
{
UNDEF,
/// Basic mode cannot be used with this arch.
BASIC_MODE,
/// Extra mode cannot be used with this arch.
EXTRA_MODE,
/// Translator cannnot change basic mode for this architecture.
BASIC_MODE_CHANGE
};

public:
ModeSettingError(cs_arch a, cs_mode m, eType t);

std::string getMessage() const;
virtual const char* what() const noexcept override;

private:
cs_arch _arch = CS_ARCH_ALL;
cs_mode _mode = CS_MODE_LITTLE_ENDIAN;
eType _type = eType::UNDEF;
class ModeSettingError : public BaseError {
public:
enum class eType
{
UNDEF,
/// Basic mode cannot be used with this arch.
BASIC_MODE,
/// Extra mode cannot be used with this arch.
EXTRA_MODE,
/// Translator cannnot change basic mode for this architecture.
BASIC_MODE_CHANGE
};

public:
ModeSettingError(cs_arch a, cs_mode m, eType t);

std::string getMessage() const;
virtual const char* what() const noexcept override;

private:
cs_arch _arch = CS_ARCH_ALL;
cs_mode _mode = CS_MODE_LITTLE_ENDIAN;
eType _type = eType::UNDEF;
std::string _whatMessage;
// Get message internal: generate message and store it to _whatMessage.
void _getMessage() noexcept;
};

/**
Expand All @@ -77,21 +77,23 @@ class ModeSettingError : public BaseError
*
* These exceptions may be suppressed and/or ignored.
*/
class UnexpectedOperandsError : public BaseError
{
public:
/**
* @param i Capstone instruction in which unexpected operand
* was encountered.
* @param comment Optional comment about the problem.
*/
UnexpectedOperandsError(cs_insn* i, const std::string& comment = "");

virtual const char* what() const noexcept override;

private:
cs_insn* _insn = nullptr;
std::string _comment;
class UnexpectedOperandsError : public BaseError {
public:
/**
* @param i Capstone instruction in which unexpected operand
* was encountered.
* @param comment Optional comment about the problem.
*/
UnexpectedOperandsError(cs_insn* i, const std::string& comment = "");

virtual const char* what() const noexcept override;

private:
cs_insn* _insn = nullptr;
std::string _comment;
std::string _whatMessage;
// Get message internal: generate message and store it to _whatMessage.
void _getMessage() noexcept;
};

/**
Expand All @@ -100,20 +102,21 @@ class UnexpectedOperandsError : public BaseError
* These exceptions may be suppressed and/or ignored. Not all instructions are
* handled, or will be handled in the future.
*/
class UnhandledInstructionError : public BaseError
{
public:
/**
* @param i Capstone instruction which is not handled.
* @param comment Optional comment about the problem.
*/
UnhandledInstructionError(cs_insn* i, const std::string& comment = "");

virtual const char* what() const noexcept override;

private:
cs_insn* _insn = nullptr;
std::string _comment;
class UnhandledInstructionError : public BaseError {
public:
/**
* @param i Capstone instruction which is not handled.
* @param comment Optional comment about the problem.
*/
UnhandledInstructionError(cs_insn* i, const std::string& comment = "");

virtual const char* what() const noexcept override;

private:
void _getMessage() noexcept;
cs_insn* _insn = nullptr;
std::string _comment;
std::string _whatMessage;
};

/**
Expand All @@ -122,16 +125,15 @@ class UnhandledInstructionError : public BaseError
* These exceptions signal some operational problems in Capstone2LlvmIr library.
* They should not be ignored. They should be reported to RetDec developers.
*/
class GenericError : public BaseError
{
public:
GenericError(const std::string& message);
class GenericError : public BaseError {
public:
GenericError(const std::string& message);

virtual const char* what() const noexcept override;
virtual const char* what() const noexcept override;

private:
/// Message returned by @c what() method.
std::string _whatMessage;
private:
/// Message returned by @c what() method.
std::string _whatMessage;
};

} // namespace capstone2llvmir
Expand Down
2 changes: 1 addition & 1 deletion include/retdec/llvmir2hll/hll/hll_writers/c_hll_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class CHLLWriter: public HLLWriter {
/// @}

bool shouldEmitFunctionPrototypesHeader() const;
bool emitFunctionPrototypes(const FuncSet &funcs);
bool emitFunctionPrototypes(const FuncSet& funcs) override;
bool emitStandardFunctionPrototypes();
bool emitFunctionPrototypesForNonLibraryFuncs();
bool emitFunctionPrototype(ShPtr<Function> func);
Expand Down
Loading