* < 0: error
*/
static int visit_node_load_expression_legacy(struct filter_parser_ctx *ctx,
- const struct ir_load_expression *exp,
- const struct ir_load_expression_op *op)
+ const struct ir_load_expression *exp)
{
- struct load_op *insn = NULL;
- uint32_t insn_len = sizeof(struct load_op) + sizeof(struct field_ref);
+ struct load_op *insn = nullptr;
+ const auto insn_len = sizeof(struct load_op) + sizeof(struct field_ref);
struct field_ref ref_offset;
uint32_t reloc_offset_u32;
uint16_t reloc_offset;
enum bytecode_op op_type;
- char *symbol = NULL;
+ char *symbol = nullptr;
int ret;
ret = load_expression_legacy_match(exp, &op_type, &symbol);
* TODO: if we remove legacy load for application contexts, we
* need to update session bytecode parser as well.
*/
- ret = visit_node_load_expression_legacy(ctx, exp, op);
+ ret = visit_node_load_expression_legacy(ctx, exp);
if (ret < 0) {
return ret;
}
return 0; /* legacy */
}
- for (; op != NULL; op = op->next) {
+ for (; op != nullptr; op = op->next) {
switch (op->type) {
case IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT:
{
case IR_LOAD_EXPRESSION_LOAD_FIELD:
{
struct load_op *insn;
- uint32_t insn_len = sizeof(struct load_op);
+ const auto insn_len = sizeof(struct load_op);
insn = (load_op *) calloc(insn_len, 1);
if (!insn)
case IR_DATA_STRING:
{
struct load_op *insn;
- uint32_t insn_len =
+ const auto insn_len =
sizeof(struct load_op) + strlen(node->u.load.u.string.value) + 1;
insn = (load_op *) calloc(insn_len, 1);
case IR_DATA_NUMERIC:
{
struct load_op *insn;
- uint32_t insn_len = sizeof(struct load_op) + sizeof(struct literal_numeric);
+ const auto insn_len = sizeof(struct load_op) + sizeof(struct literal_numeric);
insn = (load_op *) calloc(insn_len, 1);
if (!insn)
case IR_DATA_FLOAT:
{
struct load_op *insn;
- uint32_t insn_len = sizeof(struct load_op) + sizeof(struct literal_double);
+ const auto insn_len = sizeof(struct load_op) + sizeof(struct literal_double);
insn = (load_op *) calloc(insn_len, 1);
if (!insn)
if (ctx->bytecode) {
free(ctx->bytecode);
- ctx->bytecode = NULL;
+ ctx->bytecode = nullptr;
}
if (ctx->bytecode_reloc) {
free(ctx->bytecode_reloc);
- ctx->bytecode_reloc = NULL;
+ ctx->bytecode_reloc = nullptr;
}
}
op = zmalloc<ir_op>();
if (!op)
- return NULL;
+ return nullptr;
switch (child->data_type) {
case IR_DATA_UNKNOWN:
default:
fprintf(stderr, "[error] Unknown root child data type\n");
free(op);
- return NULL;
+ return nullptr;
case IR_DATA_STRING:
fprintf(stderr, "[error] String cannot be root data type\n");
free(op);
- return NULL;
+ return nullptr;
case IR_DATA_NUMERIC:
case IR_DATA_FIELD_REF:
case IR_DATA_GET_CONTEXT_REF:
op = zmalloc<ir_op>();
if (!op)
- return NULL;
+ return nullptr;
op->op = IR_OP_LOAD;
op->data_type = IR_DATA_STRING;
op->signedness = IR_SIGN_UNKNOWN;
op->u.load.u.string.value = strdup(string);
if (!op->u.load.u.string.value) {
free(op);
- return NULL;
+ return nullptr;
}
return op;
}
op = zmalloc<ir_op>();
if (!op)
- return NULL;
+ return nullptr;
op->op = IR_OP_LOAD;
op->data_type = IR_DATA_NUMERIC;
/* TODO: for now, all numeric values are signed */
op = zmalloc<ir_op>();
if (!op)
- return NULL;
+ return nullptr;
op->op = IR_OP_LOAD;
op->data_type = IR_DATA_FLOAT;
op->signedness = IR_SIGN_UNKNOWN;
/* Get forward chain. */
node = load_expression_get_forward_chain(node);
if (!node)
- return NULL;
+ return nullptr;
load_exp = zmalloc<ir_load_expression>();
if (!load_exp)
- return NULL;
+ return nullptr;
/* Root */
load_exp_op = zmalloc<ir_load_expression_op>();
goto error;
/* Explore brackets from current node. */
- for (bracket_node = node->u.expression.next_bracket; bracket_node != NULL;
+ for (bracket_node = node->u.expression.next_bracket; bracket_node != nullptr;
bracket_node = bracket_node->u.expression.next_bracket) {
prev_op = load_exp_op;
if (bracket_node->type != NODE_EXPRESSION ||
error:
free_load_expression(load_exp);
- return NULL;
+ return nullptr;
}
static struct ir_op *make_op_load_expression(struct filter_node *node, enum ir_side side)
op = zmalloc<ir_op>();
if (!op)
- return NULL;
+ return nullptr;
op->op = IR_OP_LOAD;
op->data_type = IR_DATA_EXPRESSION;
op->signedness = IR_SIGN_DYN;
error:
free_load_expression(op->u.load.u.expression);
free(op);
- return NULL;
+ return nullptr;
}
static struct ir_op *make_op_unary(enum unary_op_type unary_op_type,
struct ir_op *child,
enum ir_side side)
{
- struct ir_op *op = NULL;
+ struct ir_op *op = nullptr;
if (child->data_type == IR_DATA_STRING) {
fprintf(stderr,
op = zmalloc<ir_op>();
if (!op)
- return NULL;
+ return nullptr;
op->op = IR_OP_UNARY;
op->data_type = child->data_type;
op->signedness = signedness;
error:
free(op);
- return NULL;
+ return nullptr;
}
/*
struct ir_op *right,
enum ir_side side)
{
- struct ir_op *op = NULL;
+ struct ir_op *op = nullptr;
if (left->data_type == IR_DATA_UNKNOWN || right->data_type == IR_DATA_UNKNOWN) {
fprintf(stderr, "[error] binary operation '%s' has unknown operand type\n", op_str);
op = zmalloc<ir_op>();
if (!op)
- return NULL;
+ return nullptr;
op->op = IR_OP_BINARY;
op->u.binary.type = bin_op_type;
op->u.binary.left = left;
error:
free(op);
- return NULL;
+ return nullptr;
}
static struct ir_op *make_op_binary_eq(struct ir_op *left, struct ir_op *right, enum ir_side side)
struct ir_op *right,
enum ir_side side)
{
- struct ir_op *op = NULL;
+ struct ir_op *op = nullptr;
if (left->data_type == IR_DATA_UNKNOWN || right->data_type == IR_DATA_UNKNOWN) {
fprintf(stderr, "[error] binary operation '%s' has unknown operand type\n", op_str);
op = zmalloc<ir_op>();
if (!op)
- return NULL;
+ return nullptr;
op->op = IR_OP_LOGICAL;
op->u.binary.type = bin_op_type;
op->u.binary.left = left;
error:
free(op);
- return NULL;
+ return nullptr;
}
static struct ir_op *make_op_binary_bitwise(enum op_type bin_op_type,
struct ir_op *right,
enum ir_side side)
{
- struct ir_op *op = NULL;
+ struct ir_op *op = nullptr;
if (left->data_type == IR_DATA_UNKNOWN || right->data_type == IR_DATA_UNKNOWN) {
fprintf(stderr,
op = zmalloc<ir_op>();
if (!op)
- return NULL;
+ return nullptr;
op->op = IR_OP_BINARY;
op->u.binary.type = bin_op_type;
op->u.binary.left = left;
error:
free(op);
- return NULL;
+ return nullptr;
}
static struct ir_op *
case AST_EXP_UNKNOWN:
default:
fprintf(stderr, "[error] %s: unknown expression type\n", __func__);
- return NULL;
+ return nullptr;
case AST_EXP_STRING:
return make_op_load_string(node->u.expression.u.string, side);
static struct ir_op *
make_op(struct filter_parser_ctx *ctx, struct filter_node *node, enum ir_side side)
{
- struct ir_op *op = NULL, *lchild, *rchild;
+ struct ir_op *op = nullptr, *lchild, *rchild;
const char *op_str = "?";
switch (node->u.op.type) {
case AST_OP_UNKNOWN:
default:
fprintf(stderr, "[error] %s: unknown binary op type\n", __func__);
- return NULL;
+ return nullptr;
/*
* The following binary operators other than comparators and
case AST_OP_BIT_XOR:
lchild = generate_ir_recursive(ctx, node->u.op.lchild, IR_LEFT);
if (!lchild)
- return NULL;
+ return nullptr;
rchild = generate_ir_recursive(ctx, node->u.op.rchild, IR_RIGHT);
if (!rchild) {
filter_free_ir_recursive(lchild);
- return NULL;
+ return nullptr;
}
break;
case AST_OP_LE:
lchild = generate_ir_recursive(ctx, node->u.op.lchild, IR_LEFT);
if (!lchild)
- return NULL;
+ return nullptr;
rchild = generate_ir_recursive(ctx, node->u.op.rchild, IR_RIGHT);
if (!rchild) {
filter_free_ir_recursive(lchild);
- return NULL;
+ return nullptr;
}
break;
*/
lchild = generate_ir_recursive(ctx, node->u.op.lchild, IR_LEFT);
if (!lchild)
- return NULL;
+ return nullptr;
rchild = generate_ir_recursive(ctx, node->u.op.rchild, IR_LEFT);
if (!rchild) {
filter_free_ir_recursive(lchild);
- return NULL;
+ return nullptr;
}
break;
}
error_not_supported:
fprintf(stderr, "[error] %s: binary operation '%s' not supported\n", __func__, op_str);
- return NULL;
+ return nullptr;
}
static struct ir_op *
case AST_UNARY_UNKNOWN:
default:
fprintf(stderr, "[error] %s: unknown unary op type\n", __func__);
- return NULL;
+ return nullptr;
case AST_UNARY_PLUS:
{
child = generate_ir_recursive(ctx, node->u.unary_op.child, side);
if (!child)
- return NULL;
+ return nullptr;
op = make_op_unary_plus(child, side);
if (!op) {
filter_free_ir_recursive(child);
- return NULL;
+ return nullptr;
}
return op;
}
child = generate_ir_recursive(ctx, node->u.unary_op.child, side);
if (!child)
- return NULL;
+ return nullptr;
op = make_op_unary_minus(child, side);
if (!op) {
filter_free_ir_recursive(child);
- return NULL;
+ return nullptr;
}
return op;
}
child = generate_ir_recursive(ctx, node->u.unary_op.child, side);
if (!child)
- return NULL;
+ return nullptr;
op = make_op_unary_not(child, side);
if (!op) {
filter_free_ir_recursive(child);
- return NULL;
+ return nullptr;
}
return op;
}
child = generate_ir_recursive(ctx, node->u.unary_op.child, side);
if (!child)
- return NULL;
+ return nullptr;
op = make_op_unary_bit_not(child, side);
if (!op) {
filter_free_ir_recursive(child);
- return NULL;
+ return nullptr;
}
return op;
}
}
- return NULL;
+ return nullptr;
}
static struct ir_op *
case NODE_UNKNOWN:
default:
fprintf(stderr, "[error] %s: unknown node type\n", __func__);
- return NULL;
+ return nullptr;
case NODE_ROOT:
{
child = generate_ir_recursive(ctx, node->u.root.child, side);
if (!child)
- return NULL;
+ return nullptr;
op = make_op_root(child, side);
if (!op) {
filter_free_ir_recursive(child);
- return NULL;
+ return nullptr;
}
return op;
}
case NODE_UNARY_OP:
return make_unary_op(ctx, node, side);
}
- return 0;
+ return nullptr;
}
void filter_ir_free(struct filter_parser_ctx *ctx)
{
filter_free_ir_recursive(ctx->ir_root);
- ctx->ir_root = NULL;
+ ctx->ir_root = nullptr;
}
int filter_visitor_ir_generate(struct filter_parser_ctx *ctx)