// SPDX-FileCopyrightText: 2026 RizinOrg <info@rizin.re>
// SPDX-License-Identifier: LGPL-3.0-only

/**
 * \file native_shim.c
 *
 * Build-machine (native) variant of the RzNum tree-sitter entry points.
 *
 * When cross-compiling, librz_util is also built natively so that the
 * build-time sdb_gen tool can run. That tool never evaluates RzNum
 * expressions, so the native build deliberately leaves out the
 * tree-sitter based evaluator (num/evaluator.c and friends)
 * and, with it, the whole tree-sitter dependency. unum.c still links
 * against two of the evaluator's symbols, though, so this small shim
 * provides them with behaviour that is correct for the native build:
 *
 *   - rz_num_math_value() reports a parse error. With the legacy
 *     calculator now removed, rz_num_math_ut64() has no fallback and
 *     simply yields 0 for every expression. That is harmless here:
 *     sdb_gen, the only consumer of the native library, never
 *     evaluates RzNum expressions.
 *
 *   - rz_num_value_store_free() is identical to the real one; the
 *     variable store is never populated here (nothing creates it
 *     without the evaluator), so it is only ever called with NULL.
 *
 * The regular, non-cross build never compiles this file: it uses the
 * real implementations in num/.
 */

#include <rz_util.h>

RZ_API bool rz_num_math_value(RZ_NULLABLE RzNum *num, RZ_NONNULL const char *expr,
	RZ_OUT RZ_NONNULL RzNumValue *out_value, RZ_OUT RZ_NULLABLE char **error_msg) {
	rz_return_val_if_fail(expr && out_value, false);
	(void)num;
	// No evaluator in the native build; report a parse failure. There
	// is no longer a legacy fallback, so rz_num_math_ut64() resolves
	// this to 0 (acceptable: sdb_gen never evaluates expressions).
	out_value->err = RZ_NUM_ERR_PARSE;
	if (error_msg) {
		*error_msg = NULL;
	}
	return false;
}

RZ_API void rz_num_value_store_free(RZ_NULLABLE HtSP *store) {
	ht_sp_free(store);
}
