/src/libxmlb/src/xb-opcode-private.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2018 Richard Hughes <richard@hughsie.com> |
3 | | * |
4 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <string.h> |
10 | | |
11 | | #include "xb-opcode.h" |
12 | | |
13 | | G_BEGIN_DECLS |
14 | | |
15 | | /* maximum number of tokens supported for each element -- this is a compromise |
16 | | * between making the _XbOpcode struct too large and search results */ |
17 | 0 | #define XB_OPCODE_TOKEN_MAX 32 |
18 | | |
19 | | struct _XbOpcode { |
20 | | XbOpcodeKind kind; |
21 | | guint32 val; |
22 | | gpointer ptr; |
23 | | guint8 tokens_len; |
24 | | const gchar *tokens[XB_OPCODE_TOKEN_MAX + 1]; |
25 | | GDestroyNotify destroy_func; |
26 | | guint8 level; |
27 | | }; |
28 | | |
29 | 0 | #define XB_OPCODE_INIT() {0, 0, NULL, 0, {NULL}, NULL, 0} |
30 | | |
31 | | /** |
32 | | * xb_opcode_steal: |
33 | | * @op_ptr: (transfer full): pointer to an #XbOpcode to steal |
34 | | * |
35 | | * Steal the stack-allocated #XbOpcode pointed to by @op_ptr, returning its |
36 | | * value and clearing its previous storage location using `memset()`. |
37 | | * |
38 | | * Returns: the value of @op_ptr |
39 | | * Since: 0.2.0 |
40 | | */ |
41 | | static inline XbOpcode |
42 | | xb_opcode_steal(XbOpcode *op_ptr) |
43 | 0 | { |
44 | 0 | XbOpcode op = *op_ptr; |
45 | 0 | memset(op_ptr, 0, sizeof(XbOpcode)); |
46 | 0 | return op; |
47 | 0 | } Unexecuted instantiation: xb-builder.c:xb_opcode_steal Unexecuted instantiation: xb-builder-node.c:xb_opcode_steal Unexecuted instantiation: xb-query.c:xb_opcode_steal Unexecuted instantiation: xb-silo.c:xb_opcode_steal Unexecuted instantiation: xb-silo-query.c:xb_opcode_steal Unexecuted instantiation: xb-stack.c:xb_opcode_steal Unexecuted instantiation: xb-value-bindings.c:xb_opcode_steal Unexecuted instantiation: xb-machine.c:xb_opcode_steal Unexecuted instantiation: xb-opcode.c:xb_opcode_steal |
48 | | |
49 | | void |
50 | | xb_opcode_init(XbOpcode *self, |
51 | | XbOpcodeKind kind, |
52 | | const gchar *str, |
53 | | guint32 val, |
54 | | GDestroyNotify destroy_func) G_GNUC_NON_NULL(1); |
55 | | void |
56 | | xb_opcode_clear(XbOpcode *self) G_GNUC_NON_NULL(1); |
57 | | void |
58 | | xb_opcode_bind_init(XbOpcode *self) G_GNUC_NON_NULL(1); |
59 | | gboolean |
60 | | xb_opcode_is_binding(XbOpcode *self) G_GNUC_NON_NULL(1); |
61 | | G_DEPRECATED_FOR(xb_value_bindings_bind_str) |
62 | | void |
63 | | xb_opcode_bind_str(XbOpcode *self, gchar *str, GDestroyNotify destroy_func) G_GNUC_NON_NULL(1); |
64 | | G_DEPRECATED_FOR(xb_value_bindings_bind_val) |
65 | | void |
66 | | xb_opcode_bind_val(XbOpcode *self, guint32 val) G_GNUC_NON_NULL(1); |
67 | | void |
68 | | xb_opcode_set_kind(XbOpcode *self, XbOpcodeKind kind) G_GNUC_NON_NULL(1); |
69 | | void |
70 | | xb_opcode_set_val(XbOpcode *self, guint32 val) G_GNUC_NON_NULL(1); |
71 | | gboolean |
72 | | xb_opcode_append_token(XbOpcode *self, const gchar *val) G_GNUC_NON_NULL(1, 2); |
73 | | const gchar ** |
74 | | xb_opcode_get_tokens(XbOpcode *self) G_GNUC_NON_NULL(1); |
75 | | gchar * |
76 | | xb_opcode_get_sig(XbOpcode *self) G_GNUC_NON_NULL(1); |
77 | | void |
78 | | xb_opcode_bool_init(XbOpcode *self, gboolean val) G_GNUC_NON_NULL(1); |
79 | | gboolean |
80 | | xb_opcode_has_flag(XbOpcode *self, XbOpcodeFlags flag) G_GNUC_NON_NULL(1); |
81 | | void |
82 | | xb_opcode_add_flag(XbOpcode *self, XbOpcodeFlags flag) G_GNUC_NON_NULL(1); |
83 | | |
84 | | void |
85 | | xb_opcode_set_level(XbOpcode *self, guint8 level) G_GNUC_NON_NULL(1); |
86 | | guint8 |
87 | | xb_opcode_get_level(XbOpcode *self) G_GNUC_NON_NULL(1); |
88 | | |
89 | | static inline gboolean |
90 | | _xb_opcode_has_flag(const XbOpcode *self, XbOpcodeFlags flag) |
91 | 0 | { |
92 | 0 | return (self->kind & flag) > 0; |
93 | 0 | } Unexecuted instantiation: xb-builder.c:_xb_opcode_has_flag Unexecuted instantiation: xb-builder-node.c:_xb_opcode_has_flag Unexecuted instantiation: xb-query.c:_xb_opcode_has_flag Unexecuted instantiation: xb-silo.c:_xb_opcode_has_flag Unexecuted instantiation: xb-silo-query.c:_xb_opcode_has_flag Unexecuted instantiation: xb-stack.c:_xb_opcode_has_flag Unexecuted instantiation: xb-value-bindings.c:_xb_opcode_has_flag Unexecuted instantiation: xb-machine.c:_xb_opcode_has_flag Unexecuted instantiation: xb-opcode.c:_xb_opcode_has_flag |
94 | | |
95 | | static inline XbOpcodeKind |
96 | | _xb_opcode_get_kind(const XbOpcode *self) |
97 | 0 | { |
98 | 0 | return self->kind & ~XB_OPCODE_FLAG_TOKENIZED; |
99 | 0 | } Unexecuted instantiation: xb-builder.c:_xb_opcode_get_kind Unexecuted instantiation: xb-builder-node.c:_xb_opcode_get_kind Unexecuted instantiation: xb-query.c:_xb_opcode_get_kind Unexecuted instantiation: xb-silo.c:_xb_opcode_get_kind Unexecuted instantiation: xb-silo-query.c:_xb_opcode_get_kind Unexecuted instantiation: xb-stack.c:_xb_opcode_get_kind Unexecuted instantiation: xb-value-bindings.c:_xb_opcode_get_kind Unexecuted instantiation: xb-machine.c:_xb_opcode_get_kind Unexecuted instantiation: xb-opcode.c:_xb_opcode_get_kind |
100 | | |
101 | | static inline const gchar * |
102 | | _xb_opcode_get_str(const XbOpcode *self) |
103 | 0 | { |
104 | 0 | return self->ptr; |
105 | 0 | } Unexecuted instantiation: xb-builder.c:_xb_opcode_get_str Unexecuted instantiation: xb-builder-node.c:_xb_opcode_get_str Unexecuted instantiation: xb-query.c:_xb_opcode_get_str Unexecuted instantiation: xb-silo.c:_xb_opcode_get_str Unexecuted instantiation: xb-silo-query.c:_xb_opcode_get_str Unexecuted instantiation: xb-stack.c:_xb_opcode_get_str Unexecuted instantiation: xb-value-bindings.c:_xb_opcode_get_str Unexecuted instantiation: xb-machine.c:_xb_opcode_get_str Unexecuted instantiation: xb-opcode.c:_xb_opcode_get_str |
106 | | |
107 | | static inline guint8 |
108 | | _xb_opcode_get_level(const XbOpcode *self) |
109 | 0 | { |
110 | 0 | return self->level; |
111 | 0 | } Unexecuted instantiation: xb-builder.c:_xb_opcode_get_level Unexecuted instantiation: xb-builder-node.c:_xb_opcode_get_level Unexecuted instantiation: xb-query.c:_xb_opcode_get_level Unexecuted instantiation: xb-silo.c:_xb_opcode_get_level Unexecuted instantiation: xb-silo-query.c:_xb_opcode_get_level Unexecuted instantiation: xb-stack.c:_xb_opcode_get_level Unexecuted instantiation: xb-value-bindings.c:_xb_opcode_get_level Unexecuted instantiation: xb-machine.c:_xb_opcode_get_level Unexecuted instantiation: xb-opcode.c:_xb_opcode_get_level |
112 | | |
113 | | static inline guint32 |
114 | | _xb_opcode_get_val(const XbOpcode *self) |
115 | 0 | { |
116 | 0 | return self->val; |
117 | 0 | } Unexecuted instantiation: xb-builder.c:_xb_opcode_get_val Unexecuted instantiation: xb-builder-node.c:_xb_opcode_get_val Unexecuted instantiation: xb-query.c:_xb_opcode_get_val Unexecuted instantiation: xb-silo.c:_xb_opcode_get_val Unexecuted instantiation: xb-silo-query.c:_xb_opcode_get_val Unexecuted instantiation: xb-stack.c:_xb_opcode_get_val Unexecuted instantiation: xb-value-bindings.c:_xb_opcode_get_val Unexecuted instantiation: xb-machine.c:_xb_opcode_get_val Unexecuted instantiation: xb-opcode.c:_xb_opcode_get_val |
118 | | |
119 | | static inline gboolean |
120 | | _xb_opcode_cmp_int(XbOpcode *self) |
121 | 0 | { |
122 | 0 | return self->kind == XB_OPCODE_KIND_INTEGER || self->kind == XB_OPCODE_KIND_BOOLEAN || |
123 | 0 | self->kind == XB_OPCODE_KIND_BOUND_INTEGER; |
124 | 0 | } Unexecuted instantiation: xb-builder.c:_xb_opcode_cmp_int Unexecuted instantiation: xb-builder-node.c:_xb_opcode_cmp_int Unexecuted instantiation: xb-query.c:_xb_opcode_cmp_int Unexecuted instantiation: xb-silo.c:_xb_opcode_cmp_int Unexecuted instantiation: xb-silo-query.c:_xb_opcode_cmp_int Unexecuted instantiation: xb-stack.c:_xb_opcode_cmp_int Unexecuted instantiation: xb-value-bindings.c:_xb_opcode_cmp_int Unexecuted instantiation: xb-machine.c:_xb_opcode_cmp_int Unexecuted instantiation: xb-opcode.c:_xb_opcode_cmp_int |
125 | | |
126 | | static inline gboolean |
127 | | _xb_opcode_cmp_itx(XbOpcode *self) |
128 | 0 | { |
129 | 0 | return self->kind == XB_OPCODE_KIND_INDEXED_TEXT || |
130 | 0 | self->kind == XB_OPCODE_KIND_BOUND_INDEXED_TEXT; |
131 | 0 | } Unexecuted instantiation: xb-builder.c:_xb_opcode_cmp_itx Unexecuted instantiation: xb-builder-node.c:_xb_opcode_cmp_itx Unexecuted instantiation: xb-query.c:_xb_opcode_cmp_itx Unexecuted instantiation: xb-silo.c:_xb_opcode_cmp_itx Unexecuted instantiation: xb-silo-query.c:_xb_opcode_cmp_itx Unexecuted instantiation: xb-stack.c:_xb_opcode_cmp_itx Unexecuted instantiation: xb-value-bindings.c:_xb_opcode_cmp_itx Unexecuted instantiation: xb-machine.c:_xb_opcode_cmp_itx Unexecuted instantiation: xb-opcode.c:_xb_opcode_cmp_itx |
132 | | |
133 | | G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(XbOpcode, xb_opcode_clear) |
134 | | |
135 | | G_END_DECLS |