Cthulhu  0.2.10
Cthulhu compiler collection
reflect.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 
3 #include "common.h"
4 
7 {
8  CTASSERT(field != NULL);
9 
10  return field->type;
11 }
12 
14 const cfg_info_t *cfg_get_info(const cfg_field_t *field)
15 {
16  CTASSERT(field != NULL);
17 
18  return field->info;
19 }
20 
22 const cfg_info_t *cfg_group_info(const cfg_group_t *config)
23 {
24  CTASSERT(config != NULL);
25 
26  return config->info;
27 }
28 
31 {
32  CTASSERT(config != NULL);
33 
34  return config->groups;
35 }
36 
39 {
40  CTASSERT(config != NULL);
41 
42  return config->fields;
43 }
44 
46 const cfg_int_t *cfg_int_info(const cfg_field_t *field)
47 {
48  ASSERT_FIELD_TYPE(field, eConfigInt);
49 
50  return &field->int_config;
51 }
52 
54 bool cfg_bool_info(const cfg_field_t *field)
55 {
56  ASSERT_FIELD_TYPE(field, eConfigBool);
57 
58  return field->bool_config;
59 }
60 
62 const char *cfg_string_info(const cfg_field_t *field)
63 {
64  ASSERT_FIELD_TYPE(field, eConfigString);
65 
66  return field->string_config;
67 }
68 
70 const vector_t *cfg_vector_info(const cfg_field_t *field)
71 {
72  ASSERT_FIELD_TYPE(field, eConfigVector);
73 
74  return field->vec_config;
75 }
76 
78 const cfg_enum_t *cfg_enum_info(const cfg_field_t *field)
79 {
80  ASSERT_FIELD_TYPE(field, eConfigEnum);
81 
82  return &field->enum_config;
83 }
84 
87 {
88  ASSERT_FIELD_TYPE(field, eConfigFlags);
89 
90  return &field->enum_config;
91 }
92 
93 static const char *const kConfigTypeNames[eConfigCount] = {
94 #define CFG_TYPE(id, name) [id] = (name),
95 #include "config/config.inc"
96 };
97 
99 const char *cfg_type_string(cfg_type_t type)
100 {
101  CT_ASSERT_RANGE(type, 0, eConfigCount - 1);
102 
103  return kConfigTypeNames[type];
104 }
105 
106 static const char *const kConfigArgNames[eArgCount] = {
107 #define CFG_ARG(id, name, prefix) [id] = (name),
108 #include "config/config.inc"
109 };
110 
111 STA_DECL
112 const char *cfg_arg_string(arg_style_t style)
113 {
114  CT_ASSERT_RANGE(style, 0, eArgCount - 1);
115 
116  return kConfigArgNames[style];
117 }
118 
119 static const char *const kConfigArgPrefixes[eArgCount] = {
120 #define CFG_ARG(id, name, prefix) [id] = (prefix),
121 #include "config/config.inc"
122 };
123 
124 STA_DECL
125 const char *cfg_arg_prefix(arg_style_t style)
126 {
127  CT_ASSERT_RANGE(style, 0, eArgCount - 1);
128 
129  return kConfigArgPrefixes[style];
130 }
131 
133 
134 STA_DECL
135 int cfg_int_value(const cfg_field_t *field)
136 {
137  ASSERT_FIELD_TYPE(field, eConfigInt);
138 
139  return field->int_value;
140 }
141 
142 STA_DECL
143 bool cfg_bool_value(const cfg_field_t *field)
144 {
145  ASSERT_FIELD_TYPE(field, eConfigBool);
146 
147  return field->bool_value;
148 }
149 
150 STA_DECL
151 const char *cfg_string_value(const cfg_field_t *field)
152 {
153  ASSERT_FIELD_TYPE(field, eConfigString);
154 
155  return field->string_value;
156 }
157 
158 STA_DECL
160 {
161  ASSERT_FIELD_TYPE(field, eConfigVector);
162 
163  return field->vec_value;
164 }
165 
166 STA_DECL
167 size_t cfg_enum_value(const cfg_field_t *field)
168 {
169  ASSERT_FIELD_TYPE(field, eConfigEnum);
170 
171  return field->enum_value;
172 }
173 
174 STA_DECL
175 size_t cfg_flags_value(const cfg_field_t *field)
176 {
177  ASSERT_FIELD_TYPE(field, eConfigFlags);
178 
179  return field->flags_value;
180 }
#define ASSERT_FIELD_TYPE(field, type)
Definition: common.h:43
#define STA_DECL
sal2 annotation on function implementations to copy annotations from the declaration
STA_DECL const char * cfg_string_value(const cfg_field_t *field)
get the current string value of a configuration field
Definition: reflect.c:151
STA_DECL vector_t * cfg_vector_value(const cfg_field_t *field)
get the current vector value of a configuration field
Definition: reflect.c:159
STA_DECL size_t cfg_flags_value(const cfg_field_t *field)
get the current flags value of a configuration field
Definition: reflect.c:175
STA_DECL bool cfg_bool_value(const cfg_field_t *field)
get the current boolean value of a configuration field
Definition: reflect.c:143
STA_DECL int cfg_int_value(const cfg_field_t *field)
access
Definition: reflect.c:135
STA_DECL size_t cfg_enum_value(const cfg_field_t *field)
get the current enum value of a configuration field
Definition: reflect.c:167
STA_DECL const vector_t * cfg_vector_info(const cfg_field_t *field)
get the information about a vector field
Definition: reflect.c:70
STA_DECL const char * cfg_arg_string(arg_style_t style)
get the name of an argument style
Definition: reflect.c:112
STA_DECL const char * cfg_arg_prefix(arg_style_t style)
get the prefix for an argument style
Definition: reflect.c:125
STA_DECL bool cfg_bool_info(const cfg_field_t *field)
get the information about a yes/no field
Definition: reflect.c:54
STA_DECL const cfg_info_t * cfg_group_info(const cfg_group_t *config)
get the information about a configuration group
Definition: reflect.c:22
STA_DECL const char * cfg_type_string(cfg_type_t type)
get the name of a configuration type
Definition: reflect.c:99
STA_DECL typevec_t * cfg_get_groups(const cfg_group_t *config)
get all subgroups in a configuration group
Definition: reflect.c:30
STA_DECL const cfg_int_t * cfg_int_info(const cfg_field_t *field)
get the information about an integer field
Definition: reflect.c:46
STA_DECL const cfg_enum_t * cfg_enum_info(const cfg_field_t *field)
get the information about a choice field
Definition: reflect.c:78
STA_DECL const cfg_enum_t * cfg_flags_info(const cfg_field_t *field)
get the information about a flags field
Definition: reflect.c:86
STA_DECL const char * cfg_string_info(const cfg_field_t *field)
get the information about a string field
Definition: reflect.c:62
STA_DECL vector_t * cfg_get_fields(const cfg_group_t *config)
get all fields in a configuration group
Definition: reflect.c:38
STA_DECL cfg_type_t cfg_get_type(const cfg_field_t *field)
get the type of a configuration field
Definition: reflect.c:6
STA_DECL const cfg_info_t * cfg_get_info(const cfg_field_t *field)
get the information about a configuration field
Definition: reflect.c:14
arg_style_t
Definition: config.h:38
cfg_type_t
the type of a configuration field
Definition: config.h:27
@ eArgCount
Definition: config.h:41
@ eConfigCount
Definition: config.h:31
#define CT_ASSERT_RANGE(value, min, max)
assert that a value is in a range inclusive bounds check
Definition: panic.h:148
#define CTASSERT(expr)
assert a condition, prints the condition as a message
Definition: panic.h:130
a choice from a set of options
Definition: config.h:107
vector_t * vec_value
Definition: common.h:30
const char * string_config
Definition: common.h:19
vector_t * vec_config
Definition: common.h:20
char * string_value
Definition: common.h:27
bool bool_value
Definition: common.h:26
cfg_enum_t enum_config
Definition: common.h:21
const cfg_info_t * info
Definition: common.h:14
size_t flags_value
Definition: common.h:29
int int_value
Definition: common.h:25
cfg_int_t int_config
Definition: common.h:17
size_t enum_value
Definition: common.h:28
cfg_type_t type
Definition: common.h:13
bool bool_config
Definition: common.h:18
typevec_t * groups
Definition: common.h:39
const cfg_info_t * info
Definition: common.h:37
vector_t * fields
Definition: common.h:40
information about a configuration field
Definition: config.h:69
an integer field
Definition: config.h:82
A vector with a fixed type size.
Definition: vector.h:24
a generic vector of pointers
Definition: vector.c:16