Blender V5.3
expr_pylike_eval.cc File Reference
#include <cctype>
#include <cfenv>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <variant>
#include "MEM_guardedalloc.h"
#include "BLI_alloca.hh"
#include "BLI_expr_pylike_eval.hh"
#include "BLI_math_base_c.hh"
#include "BLI_utildefines.hh"
#include "BLI_vector.hh"

Go to the source code of this file.

Classes

struct  blender::ExprOp
struct  blender::ExprPyLike_Parsed
struct  blender::BuiltinConstDef
struct  blender::BuiltinOpDef
struct  blender::KeywordTokenDef
struct  blender::ExprParseState

Namespaces

namespace  blender
 BMesh Iterators.

Macros

#define FAIL_IF(condition)

Functions

Public API
void blender::BLI_expr_pylike_free (struct ExprPyLike_Parsed *expr)
bool blender::BLI_expr_pylike_is_valid (const ExprPyLike_Parsed *expr)
bool blender::BLI_expr_pylike_is_constant (const ExprPyLike_Parsed *expr)
bool blender::BLI_expr_pylike_is_using_param (const ExprPyLike_Parsed *expr, int index)
Stack Machine Evaluation
eExprPyLike_EvalStatus blender::BLI_expr_pylike_eval (struct ExprPyLike_Parsed *expr, const double *param_values, int param_values_len, double *r_result)
Recursive Descent Parser
static bool blender::parse_expr (ExprParseState *state)
static int blender::parse_function_args (ExprParseState *state)
static bool blender::parse_unary (ExprParseState *state)
static bool blender::parse_mul (ExprParseState *state)
static bool blender::parse_add (ExprParseState *state)
static BinaryOpFunc blender::parse_get_cmp_func (short token)
static bool blender::parse_cmp_chain (ExprParseState *state, BinaryOpFunc cur_func)
static bool blender::parse_cmp (ExprParseState *state)
static bool blender::parse_not (ExprParseState *state)
static bool blender::parse_and (ExprParseState *state)
static bool blender::parse_or (ExprParseState *state)
Main Parsing Function
ExprPyLike_Parsed * blender::BLI_expr_pylike_parse (const char *expression, const char **param_names, int param_names_len)

Expression Parser State

#define MAKE_CHAR2(a, b)
#define CHECK_ERROR(condition)
#define TOKEN_ID   MAKE_CHAR2('I', 'D')
#define TOKEN_NUMBER   MAKE_CHAR2('0', '0')
#define TOKEN_GE   MAKE_CHAR2('>', '=')
#define TOKEN_LE   MAKE_CHAR2('<', '=')
#define TOKEN_NE   MAKE_CHAR2('!', '=')
#define TOKEN_EQ   MAKE_CHAR2('=', '=')
#define TOKEN_AND   MAKE_CHAR2('A', 'N')
#define TOKEN_OR   MAKE_CHAR2('O', 'R')
#define TOKEN_NOT   MAKE_CHAR2('N', 'O')
#define TOKEN_IF   MAKE_CHAR2('I', 'F')
#define TOKEN_ELSE   MAKE_CHAR2('E', 'L')
static const char * blender::token_eq_characters = "!=><"
static const char * blender::token_characters = "~`!@#$%^&*+-=/\\?:;<>(){}[]|.,\"'"
static KeywordTokenDef blender::keyword_list []
static ExprOp * blender::parse_add_op (ExprParseState *state, eOpCode code, int stack_delta)
static int blender::parse_add_jump (ExprParseState *state, eOpCode code)
static void blender::parse_set_jump (ExprParseState *state, int jump)
static bool blender::parse_add_func (ExprParseState *state, std::variant< UnaryOpFunc, BinaryOpFunc, TernaryOpFunc > funcptr)
static bool blender::parse_next_token (ExprParseState *state)

Internal Types

enum  blender::eOpCode {
  blender::OPCODE_CONST , blender::OPCODE_FUNC1 , blender::OPCODE_FUNC2 , blender::OPCODE_FUNC3 ,
  blender::OPCODE_PARAMETER , blender::OPCODE_MIN , blender::OPCODE_MAX , blender::OPCODE_JMP ,
  blender::OPCODE_JMP_ELSE , blender::OPCODE_JMP_OR , blender::OPCODE_JMP_AND , blender::OPCODE_CMP_CHAIN
}
using blender::UnaryOpFunc = double (*)(double)
using blender::BinaryOpFunc = double (*)(double, double)
using blender::TernaryOpFunc = double (*)(double, double, double)

Built-In Operations

static BuiltinConstDef blender::builtin_consts []
static BuiltinOpDef blender::builtin_ops []
static double blender::op_negate (double arg)
static double blender::op_mul (double a, double b)
static double blender::op_div (double a, double b)
static double blender::op_add (double a, double b)
static double blender::op_sub (double a, double b)
static double blender::op_radians (double arg)
static double blender::op_degrees (double arg)
static double blender::op_log2 (double a, double b)
static double blender::op_lerp (double a, double b, double x)
static double blender::op_clamp (double arg)
static double blender::op_clamp3 (double arg, double minv, double maxv)
static double blender::op_smoothstep (double a, double b, double x)
static double blender::op_not (double a)
static double blender::op_eq (double a, double b)
static double blender::op_ne (double a, double b)
static double blender::op_lt (double a, double b)
static double blender::op_le (double a, double b)
static double blender::op_gt (double a, double b)
static double blender::op_ge (double a, double b)

Detailed Description

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: min, max, 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 multi-threaded.

Definition in file expr_pylike_eval.cc.

Macro Definition Documentation

◆ CHECK_ERROR

◆ FAIL_IF

#define FAIL_IF ( condition)
Value:
if (condition) { \
return EXPR_PYLIKE_FATAL_ERROR; \
} \
((void)0)

Referenced by blender::BLI_expr_pylike_eval().

◆ MAKE_CHAR2

#define MAKE_CHAR2 ( a,
b )
Value:

Definition at line 450 of file expr_pylike_eval.cc.

Referenced by blender::parse_next_token().

◆ TOKEN_AND

#define TOKEN_AND   MAKE_CHAR2('A', 'N')

Definition at line 466 of file expr_pylike_eval.cc.

Referenced by blender::parse_and().

◆ TOKEN_ELSE

#define TOKEN_ELSE   MAKE_CHAR2('E', 'L')

Definition at line 470 of file expr_pylike_eval.cc.

Referenced by blender::parse_expr().

◆ TOKEN_EQ

#define TOKEN_EQ   MAKE_CHAR2('=', '=')

Definition at line 465 of file expr_pylike_eval.cc.

Referenced by blender::parse_get_cmp_func().

◆ TOKEN_GE

#define TOKEN_GE   MAKE_CHAR2('>', '=')

Definition at line 462 of file expr_pylike_eval.cc.

Referenced by blender::parse_get_cmp_func().

◆ TOKEN_ID

#define TOKEN_ID   MAKE_CHAR2('I', 'D')

Definition at line 460 of file expr_pylike_eval.cc.

Referenced by blender::parse_next_token(), and blender::parse_unary().

◆ TOKEN_IF

#define TOKEN_IF   MAKE_CHAR2('I', 'F')

Definition at line 469 of file expr_pylike_eval.cc.

Referenced by blender::parse_expr().

◆ TOKEN_LE

#define TOKEN_LE   MAKE_CHAR2('<', '=')

Definition at line 463 of file expr_pylike_eval.cc.

Referenced by blender::parse_get_cmp_func().

◆ TOKEN_NE

#define TOKEN_NE   MAKE_CHAR2('!', '=')

Definition at line 464 of file expr_pylike_eval.cc.

Referenced by blender::parse_get_cmp_func().

◆ TOKEN_NOT

#define TOKEN_NOT   MAKE_CHAR2('N', 'O')

Definition at line 468 of file expr_pylike_eval.cc.

Referenced by blender::parse_not().

◆ TOKEN_NUMBER

#define TOKEN_NUMBER   MAKE_CHAR2('0', '0')

Definition at line 461 of file expr_pylike_eval.cc.

Referenced by blender::parse_next_token(), and blender::parse_unary().

◆ TOKEN_OR

#define TOKEN_OR   MAKE_CHAR2('O', 'R')

Definition at line 467 of file expr_pylike_eval.cc.

Referenced by blender::parse_or().