|
@@ -17,233 +17,8 @@ |
|
|
#ifndef PARSER_COMMON_UTIL_H_ |
|
|
#ifndef PARSER_COMMON_UTIL_H_ |
|
|
#define PARSER_COMMON_UTIL_H_ |
|
|
#define PARSER_COMMON_UTIL_H_ |
|
|
|
|
|
|
|
|
|
|
|
#include "framework/common/util.h" |
|
|
#include "framework/common/debug/ge_log.h" |
|
|
#include "framework/common/debug/ge_log.h" |
|
|
#include "mmpa/mmpa_api.h" |
|
|
#include "mmpa/mmpa_api.h" |
|
|
|
|
|
|
|
|
#define CHECK_FALSE_EXEC(expr, exec_expr, ...) \ |
|
|
|
|
|
{ \ |
|
|
|
|
|
bool b = (expr); \ |
|
|
|
|
|
if (!b) { \ |
|
|
|
|
|
exec_expr; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// For propagating errors when calling a function. |
|
|
|
|
|
#define GE_RETURN_IF_ERROR(expr) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
const ::ge::Status _status = (expr); \ |
|
|
|
|
|
if (_status) return _status; \ |
|
|
|
|
|
} while (0) |
|
|
|
|
|
|
|
|
|
|
|
#define GE_RETURN_WITH_LOG_IF_ERROR(expr, ...) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
const ::ge::Status _status = (expr); \ |
|
|
|
|
|
if (_status) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, __VA_ARGS__); \ |
|
|
|
|
|
return _status; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} while (0) |
|
|
|
|
|
|
|
|
|
|
|
// check whether the parameter is true. If it is, return FAILED and record the error log |
|
|
|
|
|
#define GE_RETURN_WITH_LOG_IF_TRUE(condition, ...) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
if (condition) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, __VA_ARGS__); \ |
|
|
|
|
|
return ge::FAILED; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} while (0) |
|
|
|
|
|
|
|
|
|
|
|
// Check if the parameter is false. If yes, return FAILED and record the error log |
|
|
|
|
|
#define GE_RETURN_WITH_LOG_IF_FALSE(condition, ...) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
bool _condition = (condition); \ |
|
|
|
|
|
if (!_condition) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, __VA_ARGS__); \ |
|
|
|
|
|
return ge::FAILED; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} while (0) |
|
|
|
|
|
|
|
|
|
|
|
// Check if the parameter is false. If yes, return PARAM_INVALID and record the error log |
|
|
|
|
|
#define GE_RT_PARAM_INVALID_WITH_LOG_IF_FALSE(condition, ...) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
bool _condition = (condition); \ |
|
|
|
|
|
if (!_condition) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, __VA_ARGS__); \ |
|
|
|
|
|
return ge::PARAM_INVALID; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} while (0) |
|
|
|
|
|
|
|
|
|
|
|
// Check if the parameter is null. If yes, return PARAM_INVALID and record the error |
|
|
|
|
|
#define GE_CHECK_NOTNULL(val) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
if (val == nullptr) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, "param[%s] must not be null.", #val); \ |
|
|
|
|
|
REPORT_INNER_ERROR("E19999", "Param:%s is nullptr, check invalid", #val); \ |
|
|
|
|
|
return ge::PARAM_INVALID; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} while (0) |
|
|
|
|
|
|
|
|
|
|
|
// Check whether the parameter is null. If so, execute the exec_expr expression and record the error log |
|
|
|
|
|
#define GE_CHECK_NOTNULL_EXEC(val, exec_expr) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
if (val == nullptr) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, "param[%s] must not be null.", #val); \ |
|
|
|
|
|
exec_expr; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} while (0) |
|
|
|
|
|
|
|
|
|
|
|
// Check if the value on the left is greater than or equal to the value on the right |
|
|
|
|
|
#define GE_CHECK_GE(lhs, rhs) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
if (lhs < rhs) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, "param[%s] is less than[%s]", #lhs, #rhs); \ |
|
|
|
|
|
return ge::PARAM_INVALID; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} while (0) |
|
|
|
|
|
|
|
|
|
|
|
#define GE_DELETE_NEW_SINGLE(var) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
if (var != nullptr) { \ |
|
|
|
|
|
delete var; \ |
|
|
|
|
|
var = nullptr; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} while (0) |
|
|
|
|
|
|
|
|
|
|
|
#define GE_DELETE_NEW_ARRAY(var) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
if (var != nullptr) { \ |
|
|
|
|
|
delete[] var; \ |
|
|
|
|
|
var = nullptr; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} while (0) |
|
|
|
|
|
|
|
|
|
|
|
// If expr is true, execute exec_expr without printing logs |
|
|
|
|
|
#define GE_IF_BOOL_EXEC(expr, exec_expr) \ |
|
|
|
|
|
{ \ |
|
|
|
|
|
if (expr) { \ |
|
|
|
|
|
exec_expr; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If expr is not true, print the log and execute a custom statement |
|
|
|
|
|
#define GE_CHK_BOOL_TRUE_EXEC_INFO(expr, exec_expr, ...) \ |
|
|
|
|
|
{ \ |
|
|
|
|
|
bool b = (expr); \ |
|
|
|
|
|
if (b) { \ |
|
|
|
|
|
GELOGI(__VA_ARGS__); \ |
|
|
|
|
|
exec_expr; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If expr is not true, print the log and return the specified status |
|
|
|
|
|
#define GE_CHK_BOOL_RET_STATUS(expr, _status, ...) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
bool b = (expr); \ |
|
|
|
|
|
if (!b) { \ |
|
|
|
|
|
GELOGE(_status, __VA_ARGS__); \ |
|
|
|
|
|
return _status; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} while (0); |
|
|
|
|
|
|
|
|
|
|
|
// If expr is not SUCCESS, print the log and execute the expression + return _status |
|
|
|
|
|
#define GE_CHK_BOOL_TRUE_EXEC_RET_STATUS(expr, _status, exec_expr, ...) \ |
|
|
|
|
|
{ \ |
|
|
|
|
|
bool b = (expr); \ |
|
|
|
|
|
if (b) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, __VA_ARGS__); \ |
|
|
|
|
|
exec_expr; \ |
|
|
|
|
|
return _status; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If expr is not SUCCESS, print the log and return the same value |
|
|
|
|
|
#define GE_CHK_STATUS_RET(expr, ...) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
const ge::Status _status = (expr); \ |
|
|
|
|
|
if (_status != ge::SUCCESS) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, __VA_ARGS__); \ |
|
|
|
|
|
return _status; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} while (0); |
|
|
|
|
|
|
|
|
|
|
|
// If expr is true, print logs and execute custom statements |
|
|
|
|
|
#define GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(expr, exec_expr, ...) \ |
|
|
|
|
|
{ \ |
|
|
|
|
|
bool b = (expr); \ |
|
|
|
|
|
if (b) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, __VA_ARGS__); \ |
|
|
|
|
|
exec_expr; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If expr is not SUCCESS, print the log and do not execute return |
|
|
|
|
|
#define GE_CHK_STATUS(expr, ...) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
const ge::Status _status = (expr); \ |
|
|
|
|
|
if (_status != ge::SUCCESS) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, __VA_ARGS__); \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} while (0); |
|
|
|
|
|
|
|
|
|
|
|
#define GE_LOGE_IF(condition, ...) \ |
|
|
|
|
|
if ((condition)) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, __VA_ARGS__); \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If expr is not true, print the log and execute a custom statement |
|
|
|
|
|
#define GE_CHK_BOOL_EXEC(expr, exec_expr, ...) \ |
|
|
|
|
|
{ \ |
|
|
|
|
|
bool b = (expr); \ |
|
|
|
|
|
if (!b) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, __VA_ARGS__); \ |
|
|
|
|
|
exec_expr; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ge marco |
|
|
|
|
|
#define GE_LOGI_IF(condition, ...) \ |
|
|
|
|
|
if ((condition)) { \ |
|
|
|
|
|
GELOGI(__VA_ARGS__); \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define GE_LOGW_IF(condition, ...) \ |
|
|
|
|
|
if ((condition)) { \ |
|
|
|
|
|
GELOGW(__VA_ARGS__); \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If expr is not true, execute a custom statement |
|
|
|
|
|
#define GE_CHK_BOOL_EXEC_NOLOG(expr, exec_expr) \ |
|
|
|
|
|
{ \ |
|
|
|
|
|
bool b = (expr); \ |
|
|
|
|
|
if (!b) { \ |
|
|
|
|
|
exec_expr; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If expr is not SUCCESS, print the log and execute a custom statement |
|
|
|
|
|
#define GE_CHK_STATUS_EXEC(expr, exec_expr, ...) \ |
|
|
|
|
|
do { \ |
|
|
|
|
|
const ge::Status _status = (expr); \ |
|
|
|
|
|
GE_CHK_BOOL_EXEC(_status == SUCCESS, exec_expr, __VA_ARGS__); \ |
|
|
|
|
|
} while (0); |
|
|
|
|
|
|
|
|
|
|
|
// If expr is not true, print the log and execute a custom statement |
|
|
|
|
|
#define GE_CHK_BOOL_EXEC_INFO(expr, exec_expr, ...) \ |
|
|
|
|
|
{ \ |
|
|
|
|
|
bool b = (expr); \ |
|
|
|
|
|
if (!b) { \ |
|
|
|
|
|
GELOGI(__VA_ARGS__); \ |
|
|
|
|
|
exec_expr; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If make_shared is abnormal, print the log and execute the statement |
|
|
|
|
|
#define GE_MAKE_SHARED(exec_expr0, exec_expr1) \ |
|
|
|
|
|
try { \ |
|
|
|
|
|
exec_expr0; \ |
|
|
|
|
|
} catch (const std::bad_alloc &) { \ |
|
|
|
|
|
GELOGE(ge::FAILED, "Make shared failed"); \ |
|
|
|
|
|
exec_expr1; \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif // PARSER_COMMON_UTIL_H_ |
|
|
#endif // PARSER_COMMON_UTIL_H_ |