From 86904d513734134beffc29c6f4012d53a99f25c5 Mon Sep 17 00:00:00 2001 From: Ferenc Szontágh <szf@fsociety.hu> Date: Sun, 13 Apr 2025 15:38:34 +0000 Subject: [PATCH] some clean up, added function declaration --- src/ScriptExceptionMacros.h | 40 ++++++++++++++++++++++++++++++++-------- 1 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/ScriptExceptionMacros.h b/src/ScriptExceptionMacros.h index 31fa7da..c2e754f 100644 --- a/src/ScriptExceptionMacros.h +++ b/src/ScriptExceptionMacros.h @@ -1,19 +1,43 @@ #ifndef SCRIPT_EXCEPTION_MACROS_H #define SCRIPT_EXCEPTION_MACROS_H +#include "ScriptException.hpp" + +// +// Purpose of macros: unified exception handling with extended error information (source file and line number) +// + +// Invalid token type - expected different type #define THROW_UNEXPECTED_TOKEN_ERROR(token, expected) \ - ScriptInterpreter::throwUnexpectedTokenError(token, expected, __FILE__, __LINE__) + throw ScriptException::makeUnexpectedTokenError(token, expected, __FILE__, __LINE__) +#define THROW_UNEXPECTED_TOKEN_ERROR_HELPER(token, expected, file, line) \ + throw ScriptException::makeUnexpectedTokenError(token, expected, file, line) + +// Accessing unknown (undefined) variable #define THROW_UNDEFINED_VARIABLE_ERROR(name, token) \ - ScriptInterpreter::throwUndefinedVariableError(name, token, __FILE__, __LINE__) + throw ScriptException::makeUndefinedVariableError(name, token, __FILE__, __LINE__) -#define THROW_VARIABLE_TYPE_MISSMATCH_ERROR(target_variable_name, target_variable_type, source_variable_name, \ - source_variable_type, token) \ - ScriptInterpreter::throwVariableTypeMissmatchError(target_variable_name, target_variable_type, \ - source_variable_name, source_variable_type, token, __FILE__, \ - __LINE__) +// Unknown (undefined) function call +#define THROW_UNDEFINED_FUNCTION_ERROR(name, token) \ + throw ScriptException::makeUndefinedFunctionError(name, token, __FILE__, __LINE__) +// Variable type mismatch - e.g. string instead of number +#define THROW_VARIABLE_TYPE_MISSMATCH_ERROR(target_variable_name, target_variable_type, source_variable_name, \ + source_variable_type, token) \ + throw ScriptException::makeVariableTypeMismatchError(target_variable_name, target_variable_type, \ + source_variable_name, source_variable_type, token, __FILE__, \ + __LINE__) + +// Redefining a variable with the same name is not allowed #define THROW_VARIABLE_REDEFINITION_ERROR(name, token) \ - ScriptInterpreter::throwVariableRedefinitionError(name, token, __FILE__, __LINE__) + throw ScriptException::makeVariableRedefinitionError(name, token, __FILE__, __LINE__) + +#define THROW_FUNCTION_REDEFINITION_ERROR(name, token) \ + throw ScriptException::makeFunctionRedefinitionError(name, token, __FILE__, __LINE__) + +// Invalid or incorrect function argument +#define THROW_INVALID_FUNCTION_ARGUMENT_ERROR(functionName, argName, token) \ + throw ScriptException::makeFunctionInvalidArgumentError(functionName, argName, token, __FILE__, __LINE__) #endif // SCRIPT_EXCEPTION_MACROS_H -- Gitblit v1.9.3