[Bf-blender-cvs] [3aea5695bbd] blender2.8: Cleanup: rename BLI_simple_expr -> BLI_expr_pylike_eval
Campbell Barton
noreply at git.blender.org
Wed Sep 19 02:56:23 CEST 2018
Commit: 3aea5695bbdcf83c5c7769a629e0a2e4db0c85bc
Author: Campbell Barton
Date: Wed Sep 19 10:40:35 2018 +1000
Branches: blender2.8
https://developer.blender.org/rB3aea5695bbdcf83c5c7769a629e0a2e4db0c85bc
Cleanup: rename BLI_simple_expr -> BLI_expr_pylike_eval
Simple isn't a good prefix for library names since
lots of unrelated modules could be called 'simple'.
Include 'py' in module name since this is a subset of Python,
one of the main motivations for this is to be Python like/compatible.
===================================================================
M source/blender/blenkernel/intern/fcurve.c
A source/blender/blenlib/BLI_expr_pylike_eval.h
D source/blender/blenlib/BLI_simple_expr.h
M source/blender/blenlib/CMakeLists.txt
R086 source/blender/blenlib/intern/simple_expr.c source/blender/blenlib/intern/expr_pylike_eval.c
M source/blender/makesdna/DNA_anim_types.h
R060 tests/gtests/blenlib/BLI_simple_expr_test.cc tests/gtests/blenlib/BLI_expr_pylike_eval_test.cc
M tests/gtests/blenlib/CMakeLists.txt
===================================================================
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index bf8d259d59c..ddbe203d1af 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -49,7 +49,7 @@
#include "BLI_threads.h"
#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
-#include "BLI_simple_expr.h"
+#include "BLI_expr_pylike_eval.h"
#include "BLI_alloca.h"
#include "BLT_translation.h"
@@ -1866,7 +1866,7 @@ void fcurve_free_driver(FCurve *fcu)
BPY_DECREF(driver->expr_comp);
#endif
- BLI_simple_expr_free(driver->expr_simple);
+ BLI_expr_pylike_free(driver->expr_simple);
/* free driver itself, then set F-Curve's point to this to NULL (as the curve may still be used) */
MEM_freeN(driver);
@@ -1897,7 +1897,7 @@ ChannelDriver *fcurve_copy_driver(const ChannelDriver *driver)
/* Driver Expression Evaluation --------------- */
-static ParsedSimpleExpr *driver_compile_simple_expr_impl(ChannelDriver *driver)
+static ExprPyLike_Parsed *driver_compile_simple_expr_impl(ChannelDriver *driver)
{
/* Prepare parameter names. */
int num_vars = BLI_listbase_count(&driver->variables);
@@ -1910,10 +1910,10 @@ static ParsedSimpleExpr *driver_compile_simple_expr_impl(ChannelDriver *driver)
names[i++] = dvar->name;
}
- return BLI_simple_expr_parse(driver->expression, num_vars + 1, names);
+ return BLI_expr_pylike_parse(driver->expression, num_vars + 1, names);
}
-static bool driver_evaluate_simple_expr(ChannelDriver *driver, ParsedSimpleExpr *expr, float *result, float time)
+static bool driver_evaluate_simple_expr(ChannelDriver *driver, ExprPyLike_Parsed *expr, float *result, float time)
{
/* Prepare parameter values. */
int num_vars = BLI_listbase_count(&driver->variables);
@@ -1928,19 +1928,19 @@ static bool driver_evaluate_simple_expr(ChannelDriver *driver, ParsedSimpleExpr
/* Evaluate expression. */
double result_val;
- eSimpleExpr_EvalStatus status = BLI_simple_expr_evaluate(expr, &result_val, num_vars + 1, vars);
+ eExprPyLike_EvalStatus status = BLI_expr_pylike_eval(expr, &result_val, num_vars + 1, vars);
const char *message;
switch (status) {
- case SIMPLE_EXPR_SUCCESS:
+ case EXPR_PYLIKE_SUCCESS:
if (isfinite(result_val)) {
*result = (float)result_val;
}
return true;
- case SIMPLE_EXPR_DIV_BY_ZERO:
- case SIMPLE_EXPR_MATH_ERROR:
- message = (status == SIMPLE_EXPR_DIV_BY_ZERO) ? "Division by Zero" : "Math Domain Error";
+ case EXPR_PYLIKE_DIV_BY_ZERO:
+ case EXPR_PYLIKE_MATH_ERROR:
+ message = (status == EXPR_PYLIKE_DIV_BY_ZERO) ? "Division by Zero" : "Math Domain Error";
fprintf(stderr, "\n%s in Driver: '%s'\n", message, driver->expression);
driver->flag |= DRIVER_FLAG_INVALID;
@@ -1966,12 +1966,12 @@ static bool driver_compile_simple_expr(ChannelDriver *driver)
/* It's safe to parse in multiple threads; at worst it'll
* waste some effort, but in return avoids mutex contention. */
- ParsedSimpleExpr *expr = driver_compile_simple_expr_impl(driver);
+ ExprPyLike_Parsed *expr = driver_compile_simple_expr_impl(driver);
/* Store the result if the field is still NULL, or discard
* it if another thread got here first. */
if (atomic_cas_ptr((void **)&driver->expr_simple, NULL, expr) != NULL) {
- BLI_simple_expr_free(expr);
+ BLI_expr_pylike_free(expr);
}
return true;
@@ -1984,21 +1984,21 @@ static bool driver_try_evaluate_simple_expr(ChannelDriver *driver, ChannelDriver
*result = 0.0f;
return driver_compile_simple_expr(driver_orig) &&
- BLI_simple_expr_is_valid(driver_orig->expr_simple) &&
+ BLI_expr_pylike_is_valid(driver_orig->expr_simple) &&
driver_evaluate_simple_expr(driver, driver_orig->expr_simple, result, time);
}
/* Check if the expression in the driver conforms to the simple subset. */
bool BKE_driver_has_simple_expression(ChannelDriver *driver)
{
- return driver_compile_simple_expr(driver) && BLI_simple_expr_is_valid(driver->expr_simple);
+ return driver_compile_simple_expr(driver) && BLI_expr_pylike_is_valid(driver->expr_simple);
}
/* Reset cached compiled expression data */
void BKE_driver_invalidate_expression(ChannelDriver *driver, bool expr_changed, bool varname_changed)
{
if (expr_changed || varname_changed) {
- BLI_simple_expr_free(driver->expr_simple);
+ BLI_expr_pylike_free(driver->expr_simple);
driver->expr_simple = NULL;
}
diff --git a/source/blender/blenlib/BLI_expr_pylike_eval.h b/source/blender/blenlib/BLI_expr_pylike_eval.h
new file mode 100644
index 00000000000..b627664cc14
--- /dev/null
+++ b/source/blender/blenlib/BLI_expr_pylike_eval.h
@@ -0,0 +1,63 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2018 Blender Foundation, Alexander Gavrilov
+ * All rights reserved.
+ *
+ * Contributor(s): Alexander Gavrilov
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLI_EXPR_PYLIKE_EVAL_H__
+#define __BLI_EXPR_PYLIKE_EVAL_H__
+
+/** \file BLI_expr_pylike_eval.h
+ * \ingroup bli
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** Opaque structure containing pre-parsed data for evaluation. */
+typedef struct ExprPyLike_Parsed ExprPyLike_Parsed;
+
+/** Expression evaluation return code. */
+typedef enum eExprPyLike_EvalStatus {
+ EXPR_PYLIKE_SUCCESS = 0,
+ /* Computation errors; result is still set, but may be NaN */
+ EXPR_PYLIKE_DIV_BY_ZERO,
+ EXPR_PYLIKE_MATH_ERROR,
+ /* Expression dependent errors or bugs; result is 0 */
+ EXPR_PYLIKE_INVALID,
+ EXPR_PYLIKE_FATAL_ERROR,
+} eExprPyLike_EvalStatus;
+
+void BLI_expr_pylike_free(struct ExprPyLike_Parsed *expr);
+bool BLI_expr_pylike_is_valid(struct ExprPyLike_Parsed *expr);
+bool BLI_expr_pylike_is_constant(struct ExprPyLike_Parsed *expr);
+ExprPyLike_Parsed *BLI_expr_pylike_parse(
+ const char *expression, int num_params, const char **param_names);
+eExprPyLike_EvalStatus BLI_expr_pylike_eval(
+ struct ExprPyLike_Parsed *expr, double *result, int num_params, const double *params);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BLI_EXPR_PYLIKE_EVALUATE_H__ */
diff --git a/source/blender/blenlib/BLI_simple_expr.h b/source/blender/blenlib/BLI_simple_expr.h
deleted file mode 100644
index 8498f1a02e7..00000000000
--- a/source/blender/blenlib/BLI_simple_expr.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2018 Blender Foundation, Alexander Gavrilov
- * All rights reserved.
- *
- * Contributor(s): Alexander Gavrilov
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __BLI_SIMPLE_EXPR_H__
-#define __BLI_SIMPLE_EXPR_H__
-
-/** \file BLI_simple_expr.h
- * \ingroup bli
- * \author Alexander Gavrilov
- * \since 2018
- *
- * Simple evaluator for a subset of Python expressions that can be
- * computed using purely double precision floating point values.
- *
- * Supported subset:
- *
- * - Identifiers use only ASCII characters.
- * - Literals:
- * floating point and decimal integer.
- * - Constants:
- * pi, True, False
- * - Operators:
- * +, -, *, /, ==, !=, <, <=, >, >=, and, or, not, ternary if
- * - Functions:
- * radians, degrees,
- * abs, fabs, floor, ceil, trunc, int,
- * sin, cos, tan, asin, acos, atan, atan2,
- * exp, log, sqrt, pow, fmod
- *
- * The implementation has no global state and can be used multithreaded.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/** Opaque structure containing pre-parsed data for evaluation. */
-typedef struct ParsedSimpleExpr ParsedSimpleExpr;
-
-/** Simple expression evaluation return code. */
-typedef enum eSimpleExpr_EvalStatus {
- SIMPLE_EXPR_SUCCESS = 0,
- /* Computation errors; result is still set, but may be NaN */
- SIMPLE_EXPR_DIV_BY_ZERO,
- SIMPLE_EXPR_MATH_ERROR,
- /* Expression dependent errors or bugs; result is 0 */
- SIMPLE_EXPR_INVALID,
- SIMPLE_EXPR_FATAL_ERROR,
-} eSimpleExpr_EvalStatus;
-
-/** Free the parsed data; NULL argument is ok. */
-void BLI_simple_expr_free(struct ParsedSimpleExpr *expr);
-
-/** Check if the parsing result is valid for evaluation. */
-bool BLI_simple_expr_is_valid(struct ParsedSimpleExpr *expr);
-
-/** Check if the parsed expression always evaluates to the same value. */
-bool BLI_simple_expr_is_constant(struct ParsedSimpleExpr *expr);
-
-/** Parse the expression for evaluation later.
- * Returns non-NULL even on failure; use is_valid to check.
- */
-ParsedSimpleExpr *BLI_simple_expr_parse(const char *expression, int num_params, const char **param_names);
-
-/** Evaluate the expression with the given parameters.
- * The order and number of parameters must match the names given to parse.
- */
-eSimpleExpr_EvalStatus BLI_simple_expr_evaluate(struct ParsedSimpleE
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list