idlc 1.5.14
Interface Definition Language Compiler
Loading...
Searching...
No Matches
idl-options.h
Go to the documentation of this file.
1/**
2 * @file idl-options.h
3 * @brief Compiler options.
4 * @details This is where the structures and various compilation options are located.
5 * @author Vladimir Shaleev <vladimirshaleev@gmail.com>
6 * @ingroup files
7 * @copyright MIT License
8 */
9#ifndef IDL_OPTIONS_H
10#define IDL_OPTIONS_H
11
12#include "idl-results.h"
13
15
16/**
17 * @brief Source code.
18 * @details Used to provide source code in memory.
19 * @ingroup structs
20 */
21typedef struct
22{
23 idl_utf8_t name; /**< Source name (used to resolve imports). */
24 const idl_char_t* data; /**< Source code. */
25 idl_uint32_t size; /**< Size of idl_source_t::data in bytes. */
26} idl_source_t;
27
28/**
29 * @brief Api version.
30 * @details Used to set ::idl_options_set_version the API version.
31 * @ingroup structs
32 */
33typedef struct
34{
35 idl_uint32_t major; /**< Major component of the version. */
36 idl_uint32_t minor; /**< Minor component of the version. */
37 idl_uint32_t micro; /**< Micro component of the version. */
38} idl_api_version_t;
39
40/**
41 * @name Function pointer types.
42 * @brief Function pointers definitions.
43 * @{
44 */
45
46/**
47 * @brief Callback to get sources.
48 * @details Used to retrieve and compile sources from memory.
49 * @param[in] name The name of the file that the compiler is trying to get (for example, when it encounters "import").
50 * @param[in] depth Current imports nesting level.
51 * @param[in] data User data specified when setting up a callback.
52 * @return Should return the source if the file can be resolved, or null to indicate
53 * to the compiler that it cannot resolve the source and should try to find
54 * the source elsewhere (e.g. via import paths).
55 * @sa If the callback allocates memory, then you can free it in the callback idl_release_import_callback_t.
56 * @ingroup types
57 */
58typedef idl_source_t*
59(*idl_import_callback_t)(idl_utf8_t name,
60 idl_uint32_t depth,
61 idl_data_t data);
62
63/**
64 * @brief Callback to release sources.
65 * @details If idl_import_callback_t allocated memory dynamically for the source, you can free it here.
66 * @param[in] source Source for release.
67 * @param[in] data User data specified when setting up a callback.
68 * @sa idl_import_callback_t.
69 * @ingroup types
70 */
71typedef void
72(*idl_release_import_callback_t)(idl_source_t* source,
73 idl_data_t data);
74
75/**
76 * @brief Callback to which the compilation result is passed.
77 * @details If you need to save the compilation result to a location other than the file
78 * system, such as the network or console output, you can use this callback.
79 * @param[in] source Source of compiler output.
80 * @param[in] data User data specified when setting up a callback.
81 * @note The compiler can output multiple sources. The exact number depends on the selected generator ::idl_generator_t.
82 * @ingroup types
83 */
84typedef void
85(*idl_write_callback_t)(const idl_source_t* source,
86 idl_data_t data);
87
88/** @} */
89
90/**
91 * @name Functions of Options.
92 * @brief Functions for opaque type ::idl_options_t.
93 * @{
94 */
95
96/**
97 * @brief Creates new options instance.
98 * @details Creates an object for setting compiler options.
99 * @param[out] options New options instance.
100 * @return New options instance.
101 * @ingroup functions
102 */
103idl_api idl_result_t
104idl_options_create(idl_options_t* options);
105
106/**
107 * @brief Increments reference count.
108 * @details Manages options instance lifetime.
109 * @param[in] options Target options instance.
110 * @return Reference to same options.
111 * @sa ::idl_options_destroy
112 * @ingroup functions
113 */
114idl_api idl_options_t
115idl_options_reference(idl_options_t options);
116
117/**
118 * @brief Releases options instance.
119 * @details Destroys when reference count reaches zero.
120 * @param[in] options Options to destroy.
121 * @sa ::idl_options_reference
122 * @ingroup functions
123 */
124idl_api void
125idl_options_destroy(idl_options_t options);
126
127/**
128 * @brief Get debug mode.
129 * @details Return *TRUE* is debug mode enabled.
130 * @param[in] options Target options.
131 * @return *TRUE* is enabled.
132 * @sa ::idl_options_set_debug_mode
133 * @ingroup functions
134 */
136idl_options_get_debug_mode(idl_options_t options);
137
138/**
139 * @brief Set debug mode.
140 * @details Setting debug compilation output to console.
141 * @param[in] options Target options.
142 * @param[in] enable Enable debug.
143 * @sa ::idl_options_get_debug_mode
144 * @ingroup functions
145 */
146idl_api void
147idl_options_set_debug_mode(idl_options_t options,
148 idl_bool_t enable);
149
150/**
151 * @brief Get warning handling setting.
152 * @details Return *TRUE* if warnings are treated as errors.
153 * @param[in] options Target options.
154 * @return *TRUE* is enabled.
155 * @sa ::idl_options_set_warnings_as_errors
156 * @ingroup functions
157 */
160
161/**
162 * @brief Set warning handling setting.
163 * @details Setting treat warnings as errors.
164 * @param[in] options Target options.
165 * @param[in] enable Enable treat warnings as errors.
166 * @sa ::idl_options_get_warnings_as_errors
167 * @ingroup functions
168 */
169idl_api void
171 idl_bool_t enable);
172
173/**
174 * @brief Get output directory.
175 * @details Returns the path that the compiler will use to save compilation output.
176 * @param[in] options Target options.
177 * @return Directory path.
178 * @sa ::idl_options_set_output_dir
179 * @ingroup functions
180 */
182idl_options_get_output_dir(idl_options_t options);
183
184/**
185 * @brief Set output directory.
186 * @details Configure the path that the compiler will use to save compilation output.
187 * @param[in] options Target options.
188 * @param[in] dir Directory path.
189 * @note Compiler output to the file system does not occur if output via a ::idl_options_set_writer is configured.
190 * @sa ::idl_options_get_output_dir
191 * @ingroup functions
192 */
193idl_api void
194idl_options_set_output_dir(idl_options_t options,
195 idl_utf8_t dir);
196
197/**
198 * @brief Returns an array of directories to search for imports.
199 * @details These paths are used to search source code when an import is encountered during compilation.
200 * @param[in] options Target options.
201 * @param[in,out] dir_count Number of directories.
202 * @param[out] dirs Import directories.
203 * @sa ::idl_options_set_import_dirs
204 * @ingroup functions
205 */
206idl_api void
207idl_options_get_import_dirs(idl_options_t options,
208 idl_uint32_t* dir_count,
209 idl_utf8_t* dirs);
210
211/**
212 * @brief Configures directories to search for source files.
213 * @details These paths are used to search source code when an import is encountered during compilation.
214 * @param[in] options Target options.
215 * @param[in] dir_count Number of directories.
216 * @param[in] dirs Import directories.
217 * @note These paths are used when resolving imports if the callback passed to ::idl_options_set_importer
218 * did not return a source (if ::idl_options_set_importer was configured)
219 * @sa ::idl_options_get_import_dirs
220 * @ingroup functions
221 */
222idl_api void
223idl_options_set_import_dirs(idl_options_t options,
224 idl_uint32_t dir_count,
225 const idl_utf8_t* dirs);
226
227/**
228 * @brief Get the current import callback.
229 * @details Returns a callback if one has been configured.
230 * @param[in] options Target options.
231 * @param[out] data Returning a callback user data pointer (may be null).
232 * @return Returns a callback.
233 * @sa ::idl_options_set_importer
234 * @ingroup functions
235 */
236idl_api idl_import_callback_t
237idl_options_get_importer(idl_options_t options,
238 idl_data_t* data);
239
240/**
241 * @brief Set import callback.
242 * @details Used to resolve code sources, such as when the compiler encounters imports.
243 * @param[in] options Target options.
244 * @param[in] callback Callback function.
245 * @param[in] data Callback user data.
246 * @parblock
247 * @note If set, the importer will be used to resolve sources as the highest
248 * priority (then the sources passed to ::idl_compiler_compile in the *sources*
249 * argument will be used, then the directories passed to ::idl_options_set_import_dirs will be used,
250 * and then the current working directory).
251 * @endparblock
252 * @parblock
253 * @note If *file* was not passed to ::idl_compiler_compile to compile from the file system,
254 * then the importer will also be used to obtain the main (primary) file named *<input>*.
255 * @endparblock
256 * @parblock
257 * @note A typical use of an importer is to read source code from memory.
258 * @endparblock
259 * @sa ::idl_options_get_importer
260 * @ingroup functions
261 */
262idl_api void
263idl_options_set_importer(idl_options_t options,
264 idl_import_callback_t callback,
265 idl_data_t data);
266
267/**
268 * @brief Get the current release import callback.
269 * @details Callback for releasing sources allocated via ::idl_options_set_importer.
270 * @param[in] options Target options.
271 * @param[out] data Returning a callback user data pointer (may be null).
272 * @return Returns a callback.
273 * @sa ::idl_options_set_release_import
274 * @ingroup functions
275 */
277idl_options_get_release_import(idl_options_t options,
278 idl_data_t* data);
279
280/**
281 * @brief Set release import callback.
282 * @details If the callback set in ::idl_options_set_importer allocates data on the heap or creates
283 * any resources, they can be freed by the callback set here.
284 * @param[in] options Target options.
285 * @param[in] callback Callback function.
286 * @param[in] data Callback user data.
287 * @sa ::idl_options_get_release_import
288 * @ingroup functions
289 */
290idl_api void
291idl_options_set_release_import(idl_options_t options,
293 idl_data_t data);
294
295/**
296 * @brief Get the current write callback.
297 * @details Returns a callback if one has been configured.
298 * @param[in] options Target options.
299 * @param[out] data Returning a callback user data pointer (may be null).
300 * @return Returns a callback.
301 * @sa ::idl_options_set_writer
302 * @ingroup functions
303 */
305idl_options_get_writer(idl_options_t options,
306 idl_data_t* data);
307
308/**
309 * @brief Set write callback.
310 * @details Configures a callback to receive compiler output. If the callback is set, no output
311 * will be made to the file system (::idl_options_set_output_dir will also not be used).
312 * @param[in] options Target options.
313 * @param[in] callback Callback function.
314 * @param[in] data Callback user data.
315 * @note Typical uses of a writer are writing to memory or outputting to the console and the like.
316 * @sa ::idl_options_get_writer
317 * @ingroup functions
318 */
319idl_api void
320idl_options_set_writer(idl_options_t options,
321 idl_write_callback_t callback,
322 idl_data_t data);
323
324/**
325 * @brief Get additional parameters.
326 * @details Returns an array of additional parameters.
327 * @param[in] options Target options.
328 * @param[in,out] addition_count Number of additions.
329 * @param[out] additions Additions.
330 * @sa ::idl_options_set_additions
331 * @ingroup functions
332 */
333idl_api void
334idl_options_get_additions(idl_options_t options,
335 idl_uint32_t* addition_count,
336 idl_utf8_t* additions);
337
338/**
339 * @brief Set additional parameters.
340 * @details Sets additional parameters specific to the generator (::idl_generator_t).
341 * @param[in] options Target options.
342 * @param[in] addition_count Number of additions.
343 * @param[in] additions Additions.
344 * @note Supported Generators:
345 * - ::IDL_GENERATOR_C - additional headers included in the API header file
346 * and the special value `+docgroup` to add Doxygen groups;
347 * - ::IDL_GENERATOR_JAVA_SCRIPT - no specific parameters.
348 *
349 * @sa ::idl_options_get_additions
350 * @ingroup functions
351 */
352idl_api void
353idl_options_set_additions(idl_options_t options,
354 idl_uint32_t addition_count,
355 const idl_utf8_t* additions);
356
357/**
358 * @brief Get api version.
359 * @details Returns the API version or null.
360 * @param[in] options Target options.
361 * @return API version or null.
362 * @sa ::idl_options_set_version
363 * @ingroup functions
364 */
365idl_api const idl_api_version_t*
366idl_options_get_version(idl_options_t options);
367
368/**
369 * @brief Set api version.
370 * @details Sets the API version that will be saved in the compiler output.
371 * @param[in] options Target options.
372 * @param[in] version Api version.
373 * @note If not set, then the API version will be taken from the `[version(major,minor,micro)]`
374 * attribute (sample: `api Sample [version(2,3,1)]`). If the api does not have a version
375 * attribute specified, then the version will be taken as `0.0.0`.
376 * @sa ::idl_options_get_version
377 * @ingroup functions
378 */
379idl_api void
380idl_options_set_version(idl_options_t options,
381 const idl_api_version_t* version);
382
383/** @} */
384
386
387#endif /* IDL_OPTIONS_H */
void idl_options_set_import_dirs(idl_options_t options, idl_uint32_t dir_count, const idl_utf8_t *dirs)
Configures directories to search for source files.
void idl_options_set_release_import(idl_options_t options, idl_release_import_callback_t callback, idl_data_t data)
Set release import callback.
void idl_options_destroy(idl_options_t options)
Releases options instance.
void idl_options_set_debug_mode(idl_options_t options, idl_bool_t enable)
Set debug mode.
idl_utf8_t idl_options_get_output_dir(idl_options_t options)
Get output directory.
idl_release_import_callback_t idl_options_get_release_import(idl_options_t options, idl_data_t *data)
Get the current release import callback.
void idl_options_set_writer(idl_options_t options, idl_write_callback_t callback, idl_data_t data)
Set write callback.
idl_bool_t idl_options_get_warnings_as_errors(idl_options_t options)
Get warning handling setting.
idl_write_callback_t idl_options_get_writer(idl_options_t options, idl_data_t *data)
Get the current write callback.
void idl_options_set_warnings_as_errors(idl_options_t options, idl_bool_t enable)
Set warning handling setting.
idl_bool_t idl_options_get_debug_mode(idl_options_t options)
Get debug mode.
void idl_options_set_additions(idl_options_t options, idl_uint32_t addition_count, const idl_utf8_t *additions)
Set additional parameters.
const idl_api_version_t * idl_options_get_version(idl_options_t options)
Get api version.
void idl_options_set_importer(idl_options_t options, idl_import_callback_t callback, idl_data_t data)
Set import callback.
idl_import_callback_t idl_options_get_importer(idl_options_t options, idl_data_t *data)
Get the current import callback.
void idl_options_get_import_dirs(idl_options_t options, idl_uint32_t *dir_count, idl_utf8_t *dirs)
Returns an array of directories to search for imports.
void idl_options_get_additions(idl_options_t options, idl_uint32_t *addition_count, idl_utf8_t *additions)
Get additional parameters.
void idl_options_set_version(idl_options_t options, const idl_api_version_t *version)
Set api version.
idl_options_t idl_options_reference(idl_options_t options)
Increments reference count.
void idl_options_set_output_dir(idl_options_t options, idl_utf8_t dir)
Set output directory.
idl_result_t idl_options_create(idl_options_t *options)
Creates new options instance.
#define IDL_END
Ends a C-linkage declaration block.
Definition idl-platform.h:43
#define idl_api
Controls symbol visibility for shared library builds.
Definition idl-platform.h:61
#define IDL_BEGIN
Begins a C-linkage declaration block.
Definition idl-platform.h:42
void(* idl_release_import_callback_t)(idl_source_t *source, idl_data_t data)
Callback to release sources.
Definition idl-options.h:72
void * idl_data_t
pointer to data.
Definition idl-platform.h:125
void(* idl_write_callback_t)(const idl_source_t *source, idl_data_t data)
Callback to which the compilation result is passed.
Definition idl-options.h:85
int32_t idl_bool_t
boolean type.
Definition idl-platform.h:113
const char * idl_utf8_t
utf8 string.
Definition idl-platform.h:124
char idl_char_t
symbol type.
Definition idl-platform.h:112
uint32_t idl_uint32_t
32 bit unsigned integer.
Definition idl-platform.h:119
idl_uint32_t major
Major component of the version.
Definition idl-options.h:35
idl_uint32_t micro
Micro component of the version.
Definition idl-options.h:37
idl_uint32_t minor
Minor component of the version.
Definition idl-options.h:36
idl_uint32_t size
Size of idl_source_t::data in bytes.
Definition idl-options.h:25
idl_utf8_t name
Source name (used to resolve imports).
Definition idl-options.h:23
const idl_char_t * data
Source code.
Definition idl-options.h:24