DTYPE_F_PREFIX = (1 << 1),
};
+struct parse_ctx;
/**
* struct datatype
*
struct output_ctx *octx);
json_t *(*json)(const struct expr *expr,
struct output_ctx *octx);
- struct error_record *(*parse)(const struct expr *sym,
+ struct error_record *(*parse)(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res);
const struct symbol_table *sym_tbl;
unsigned int refcnt;
extern void datatype_set(struct expr *expr, const struct datatype *dtype);
extern void datatype_free(const struct datatype *dtype);
-extern struct error_record *symbol_parse(const struct expr *sym,
+struct parse_ctx {
+ struct symbol_tables *tbl;
+};
+
+extern struct error_record *symbol_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res);
extern void datatype_print(const struct expr *expr, struct output_ctx *octx);
struct symbolic_constant symbols[];
};
-extern struct error_record *symbolic_constant_parse(const struct expr *sym,
+extern struct error_record *symbolic_constant_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
const struct symbol_table *tbl,
struct expr **res);
extern void symbolic_constant_print(const struct symbol_table *tbl,
expr->dtype->name);
}
-struct error_record *symbol_parse(const struct expr *sym,
+struct error_record *symbol_parse(struct parse_ctx *ctx, const struct expr *sym,
struct expr **res)
{
const struct datatype *dtype = sym->dtype;
return error(&sym->location, "No symbol type information");
do {
if (dtype->parse != NULL)
- return dtype->parse(sym, res);
+ return dtype->parse(ctx, sym, res);
if (dtype->sym_tbl != NULL)
- return symbolic_constant_parse(sym, dtype->sym_tbl,
+ return symbolic_constant_parse(ctx, sym, dtype->sym_tbl,
res);
} while ((dtype = dtype->basetype));
sym->dtype->desc);
}
-struct error_record *symbolic_constant_parse(const struct expr *sym,
+struct error_record *symbolic_constant_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
const struct symbol_table *tbl,
struct expr **res)
{
*res = NULL;
do {
if (dtype->basetype->parse) {
- erec = dtype->basetype->parse(sym, res);
+ erec = dtype->basetype->parse(ctx, sym, res);
if (erec != NULL)
return erec;
if (*res)
}
}
-static struct error_record *verdict_type_parse(const struct expr *sym,
+static struct error_record *verdict_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
*res = constant_expr_alloc(&sym->location, &string_type,
nft_gmp_print(octx, fmt, expr->value);
}
-static struct error_record *integer_type_parse(const struct expr *sym,
+static struct error_record *integer_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
mpz_t v;
nft_print(octx, "\"%s\"", data);
}
-static struct error_record *string_type_parse(const struct expr *sym,
+static struct error_record *string_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
*res = constant_expr_alloc(&sym->location, &string_type,
}
}
-static struct error_record *lladdr_type_parse(const struct expr *sym,
+static struct error_record *lladdr_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
char buf[strlen(sym->identifier) + 1], *p;
nft_print(octx, "%s", buf);
}
-static struct error_record *ipaddr_type_parse(const struct expr *sym,
+static struct error_record *ipaddr_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
struct addrinfo *ai, hints = { .ai_family = AF_INET,
nft_print(octx, "%s", buf);
}
-static struct error_record *ip6addr_type_parse(const struct expr *sym,
+static struct error_record *ip6addr_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
struct addrinfo *ai, hints = { .ai_family = AF_INET6,
integer_type_print(expr, octx);
}
-static struct error_record *inet_protocol_type_parse(const struct expr *sym,
+static struct error_record *inet_protocol_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
struct protoent *p;
integer_type_print(expr, octx);
}
-static struct error_record *inet_service_type_parse(const struct expr *sym,
+static struct error_record *inet_service_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
struct addrinfo *ai;
return symbolic_constant_print(mark_tbl, expr, true, octx);
}
-static struct error_record *mark_type_parse(const struct expr *sym,
+static struct error_record *mark_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
- return symbolic_constant_parse(sym, mark_tbl, res);
+ return symbolic_constant_parse(ctx, sym, mark_tbl, res);
}
const struct datatype mark_type = {
time_print(mpz_get_uint64(expr->value), octx);
}
-static struct error_record *time_type_parse(const struct expr *sym,
+static struct error_record *time_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
struct error_record *erec;
.parse = time_type_parse,
};
-static struct error_record *concat_type_parse(const struct expr *sym,
+static struct error_record *concat_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
return error(&sym->location, "invalid data type, expected %s",
}
}
-static struct error_record *tchandle_type_parse(const struct expr *sym,
+static struct error_record *tchandle_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
uint32_t handle;
nft_print(octx, "%d", ifindex);
}
-static struct error_record *ifindex_type_parse(const struct expr *sym,
+static struct error_record *ifindex_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
int ifindex;
expr_basetype(expr)->print(expr, octx);
}
-static struct error_record *uid_type_parse(const struct expr *sym,
+static struct error_record *uid_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
struct passwd *pw;
expr_basetype(expr)->print(expr, octx);
}
-static struct error_record *gid_type_parse(const struct expr *sym,
+static struct error_record *gid_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
struct group *gr;
return symbolic_constant_print(devgroup_tbl, expr, true, octx);
}
-static struct error_record *devgroup_type_parse(const struct expr *sym,
+static struct error_record *devgroup_type_parse(struct parse_ctx *ctx,
+ const struct expr *sym,
struct expr **res)
{
- return symbolic_constant_parse(sym, devgroup_tbl, res);
+ return symbolic_constant_parse(ctx, sym, devgroup_tbl, res);
}
const struct datatype devgroup_type = {