cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / shaders / parser_utils.h
blob30db0b3a8d59d17171b43fb2153dc60df6c6e76f
1 /*
2 * Copyright © 2016 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 /**
25 * \file parser_utils.h
27 * These are a bunch of plain-text parsing utilities, most of them
28 * have the form:
29 * boolean-like parse_foo(input-string, output-foo, output-string)
31 * If the input is a well-formed string representation of a "foo"
32 * value, as many characters will be read from the string as they are
33 * needed to initialize the "foo" object returned via the first output
34 * argument, and the boolean return value will evaluate to true. If
35 * the output string argument is not NULL, a pointer one past the last
36 * character consumed to parse a "foo" value will be returned to the
37 * caller so that the rest of the document can be processed (e.g. by
38 * passing the output string as input string of another parse
39 * function).
41 * If the input cannot be parsed as a "foo" object, the boolean return
42 * value will evaluate to false and the input string will be returned
43 * as output string as-is (which mimics the behavior of the C
44 * standard library strto* functions). The "foo" output argument will
45 * be left in an undefined state in that case.
47 #ifndef PIGLIT_PARSER_UTILS_H
48 #define PIGLIT_PARSER_UTILS_H
50 #include <stdbool.h>
51 #include "piglit-util-gl.h"
53 /**
54 * Parse one or more whitespace characters (other than newline) from
55 * the input string.
57 bool
58 parse_whitespace(const char *s, const char **rest);
60 /**
61 * Parse an exact match of string \p lit, optionally preceded by
62 * whitespace.
64 bool
65 parse_str(const char *s, const char *lit, const char **rest);
67 /**
68 * Parse up to \p n whitespace-separated signed integer values. The
69 * number of values actually parsed is returned as result.
71 unsigned
72 parse_ints(const char *s, int *i, unsigned n, const char **rest);
74 static inline bool
75 parse_int(const char *s, int *i, const char **rest)
77 return parse_ints(s, i, 1, rest);
80 /**
81 * Parse up to \p n whitespace-separated unsigned integer values. The
82 * number of values actually parsed is returned as result.
84 unsigned
85 parse_uints(const char *s, unsigned *u, unsigned n, const char **rest);
87 static inline bool
88 parse_uint(const char *s, unsigned *u, const char **rest)
90 return parse_uints(s, u, 1, rest);
93 /**
94 * Parse up to \p n whitespace-separated signed 64-bit integer values.
95 * The number of values actually parsed is returned as result.
97 unsigned
98 parse_int64s(const char *s, int64_t *i, unsigned n, const char **rest);
100 static inline bool
101 parse_int64(const char *s, int64_t *i, const char **rest)
103 return parse_int64s(s, i, 1, rest);
107 * Parse up to \p n whitespace-separated unsigned 64-bit integer
108 * values. The number of values actually parsed is returned as
109 * result.
111 unsigned
112 parse_uint64s(const char *s, uint64_t *u, unsigned n, const char **rest);
114 static inline bool
115 parse_uint64(const char *s, uint64_t *u, const char **rest)
117 return parse_uint64s(s, u, 1, rest);
121 * Parse up to \p n whitespace-separated floating point values. The
122 * number of values actually parsed is returned as result.
124 unsigned
125 parse_floats(const char *s, float *f, unsigned n, const char **rest);
127 static inline bool
128 parse_float(const char *s, float *f, const char **rest)
130 return parse_floats(s, f, 1, rest);
134 * Parse up to \p n whitespace-separated double-precision floating
135 * point values. The number of values actually parsed is returned as
136 * result.
138 unsigned
139 parse_doubles(const char *s, double *d, unsigned n, const char **rest);
141 static inline bool
142 parse_double(const char *s, double *d, const char **rest)
144 return parse_doubles(s, d, 1, rest);
148 * Parse a single non-empty whitespace-separated token. On success \p
149 * t and \p rest will respectively point at the first and one past the
150 * last character of the result.
152 bool
153 parse_word(const char *s, const char **t, const char **rest);
156 * Like parse_word(), but the result is copied into the fixed-size
157 * buffer pointed to by \p t and null-terminated.
159 * The parse is considered to fail if the size of the result
160 * (including the terminating null character) would have exceeded the
161 * number of characters allocated for it in the buffer as given by the
162 * \p n argument.
164 bool
165 parse_word_copy(const char *s, char *t, unsigned n, const char **rest);
168 * Parse a GL_* symbolic constant.
170 bool
171 parse_enum_gl(const char *s, GLenum *e, const char **rest);
173 struct string_to_enum {
174 const char *name;
175 unsigned value;
179 * Parse a whitespace-delimited symbolic constant from the set
180 * specified in the \p tab argument pointing to a zero-terminated
181 * array of string-value pairs.
183 bool
184 parse_enum_tab(const struct string_to_enum *tab,
185 const char *s, unsigned *e, const char **rest);
188 * Parse a texture target symbolic constant.
190 bool
191 parse_tex_target(const char *s, GLenum *t, const char **rest);
193 enum comparison {
194 equal = 0,
195 not_equal,
196 less,
197 greater_equal,
198 greater,
199 less_equal
203 * Parse a binary comparison operator.
205 bool parse_comparison_op(const char *s, enum comparison *t, const char **rest);
208 * Abort the Piglit test with failure status if the boolean expression
209 * (typically the result of a chain of parse function calls) evaluates
210 * to false.
212 #define REQUIRE(b, ...) do { \
213 if (!(b)) { \
214 fprintf(stderr, __VA_ARGS__); \
215 piglit_report_result(PIGLIT_FAIL); \
217 } while (0)
219 #endif