cctools
jx_match.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2022 The University of Notre Dame
3 This software is distributed under the GNU General Public License.
4 See the file COPYING for details.
5 */
6 
88 #ifndef JX_MATCH_H
89 #define JX_MATCH_H
90 
91 #include "jx.h"
92 
93 #ifndef JX_ANY
94 #define JX_ANY -1
95 #endif
96 
97 /*
98  * Macro to test if we're using a GNU C compiler of a specific vintage
99  * or later, for e.g. features that appeared in a particular version
100  * of GNU C. Usage:
101  *
102  * #if __GNUC_PREREQ__(major, minor)
103  * ...cool feature...
104  * #else
105  * ...delete feature...
106  * #endif
107  */
108 #ifndef __GNUC_PREREQ__
109 #ifdef __GNUC__
110 #define __GNUC_PREREQ__(x, y) \
111  ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
112  (__GNUC__ > (x)))
113 #else
114 #define __GNUC_PREREQ__(x, y) 0
115 #endif
116 #endif
117 
118 #ifndef __wur
119 #if __GNUC_PREREQ__(3, 4)
120 #define __wur __attribute__((warn_unused_result))
121 #else
122 #define __wur
123 #endif
124 #endif
125 
126 #ifndef __sentinel
127 #if __GNUC_PREREQ__(4, 0)
128 #define __sentinel __attribute__((sentinel))
129 #else
130 #define __sentinel
131 #endif
132 #endif
133 
140 int jx_match_boolean(struct jx *j, int *v) __wur;
141 
148 int jx_match_integer(struct jx *j, jx_int_t *v) __wur;
149 
156 int jx_match_double(struct jx *j, double *v) __wur;
157 
176 int jx_match_string(struct jx *j, char **v) __wur;
177 
188 int jx_match_symbol(struct jx *j, char **v) __wur;
189 
205 int jx_match_array(struct jx *j, ...) __wur __sentinel;
206 
207 #endif
jx.h
jx_match_boolean
int jx_match_boolean(struct jx *j, int *v) __wur
Unwrap a boolean value.
jx_match_double
int jx_match_double(struct jx *j, double *v) __wur
Unwrap a double value.
jx_match_array
int jx_match_array(struct jx *j,...) __wur __sentinel
Destructure an array.
jx_match_string
int jx_match_string(struct jx *j, char **v) __wur
Unwrap a string value.
jx_match_symbol
int jx_match_symbol(struct jx *j, char **v) __wur
Unwrap a symbol value.
jx
JX value representing any expression type.
Definition: jx.h:117
jx_match_integer
int jx_match_integer(struct jx *j, jx_int_t *v) __wur
Unwrap an integer value.