Lines Matching refs:f

56 def write_header(f, limit=LIMIT):  argument
57 f.writeln("// Generated by %s:" % sys.argv[0])
58 f.writeln("//")
59 f.writeln("// %s" % ' '.join(sys.argv))
60 f.writeln("//")
61 f.writeln()
63 f.writeln("#include <stdbool.h>")
64 f.writeln("#include <stdint.h>")
65 f.writeln("#include <inttypes.h>")
66 f.writeln("#include <stdio.h>")
67 f.writeln("#include <string.h>")
68 f.writeln("#include <signal.h>")
70 f.writeln("#undef _FEATURES_H")
71 f.writeln()
74 f.writeln("__attribute__((unused))")
75 f.writeln("static void __pretty_assert_print_bool(")
76 f.writeln(" const void *v, size_t size) {")
77 f.writeln(" (void)size;")
78 f.writeln(" printf(\"%s\", *(const bool*)v ? \"true\" : \"false\");")
79 f.writeln("}")
80 f.writeln()
81 f.writeln("__attribute__((unused))")
82 f.writeln("static void __pretty_assert_print_int(")
83 f.writeln(" const void *v, size_t size) {")
84 f.writeln(" (void)size;")
85 f.writeln(" printf(\"%\"PRIiMAX, *(const intmax_t*)v);")
86 f.writeln("}")
87 f.writeln()
88 f.writeln("__attribute__((unused))")
89 f.writeln("static void __pretty_assert_print_ptr(")
90 f.writeln(" const void *v, size_t size) {")
91 f.writeln(" (void)size;")
92 f.writeln(" printf(\"%p\", v);")
93 f.writeln("}")
94 f.writeln()
95 f.writeln("__attribute__((unused))")
96 f.writeln("static void __pretty_assert_print_mem(")
97 f.writeln(" const void *v, size_t size) {")
98 f.writeln(" const uint8_t *v_ = v;")
99 f.writeln(" printf(\"\\\"\");")
100 f.writeln(" for (size_t i = 0; i < size && i < %d; i++) {" % limit)
101 f.writeln(" if (v_[i] >= ' ' && v_[i] <= '~') {")
102 f.writeln(" printf(\"%c\", v_[i]);")
103 f.writeln(" } else {")
104 f.writeln(" printf(\"\\\\x%02x\", v_[i]);")
105 f.writeln(" }")
106 f.writeln(" }")
107 f.writeln(" if (size > %d) {" % limit)
108 f.writeln(" printf(\"...\");")
109 f.writeln(" }")
110 f.writeln(" printf(\"\\\"\");")
111 f.writeln("}")
112 f.writeln()
113 f.writeln("__attribute__((unused))")
114 f.writeln("static void __pretty_assert_print_str(")
115 f.writeln(" const void *v, size_t size) {")
116 f.writeln(" __pretty_assert_print_mem(v, size);")
117 f.writeln("}")
118 f.writeln()
119 f.writeln("__attribute__((unused, noinline))")
120 f.writeln("static void __pretty_assert_fail(")
121 f.writeln(" const char *file, int line,")
122 f.writeln(" void (*type_print_cb)(const void*, size_t),")
123 f.writeln(" const char *cmp,")
124 f.writeln(" const void *lh, size_t lsize,")
125 f.writeln(" const void *rh, size_t rsize) {")
126 f.writeln(" printf(\"%s:%d:assert: assert failed with \", file, line);")
127 f.writeln(" type_print_cb(lh, lsize);")
128 f.writeln(" printf(\", expected %s \", cmp);")
129 f.writeln(" type_print_cb(rh, rsize);")
130 f.writeln(" printf(\"\\n\");")
131 f.writeln(" fflush(NULL);")
132 f.writeln(" raise(SIGABRT);")
133 f.writeln("}")
134 f.writeln()
138 f.writeln("#define __PRETTY_ASSERT_BOOL_%s(lh, rh) do { \\"
140 f.writeln(" bool _lh = !!(lh); \\")
141 f.writeln(" bool _rh = !!(rh); \\")
142 f.writeln(" if (!(_lh %s _rh)) { \\" % op)
143 f.writeln(" __pretty_assert_fail( \\")
144 f.writeln(" __FILE__, __LINE__, \\")
145 f.writeln(" __pretty_assert_print_bool, \"%s\", \\"
147 f.writeln(" &_lh, 0, \\")
148 f.writeln(" &_rh, 0); \\")
149 f.writeln(" } \\")
150 f.writeln("} while (0)")
152 f.writeln("#define __PRETTY_ASSERT_INT_%s(lh, rh) do { \\"
154 f.writeln(" __typeof__(lh) _lh = lh; \\")
155 f.writeln(" __typeof__(lh) _rh = rh; \\")
156 f.writeln(" if (!(_lh %s _rh)) { \\" % op)
157 f.writeln(" __pretty_assert_fail( \\")
158 f.writeln(" __FILE__, __LINE__, \\")
159 f.writeln(" __pretty_assert_print_int, \"%s\", \\"
161 f.writeln(" &(intmax_t){_lh}, 0, \\")
162 f.writeln(" &(intmax_t){_rh}, 0); \\")
163 f.writeln(" } \\")
164 f.writeln("} while (0)")
166 f.writeln("#define __PRETTY_ASSERT_MEM_%s(lh, rh, size) do { \\"
168 f.writeln(" const void *_lh = lh; \\")
169 f.writeln(" const void *_rh = rh; \\")
170 f.writeln(" if (!(memcmp(_lh, _rh, size) %s 0)) { \\" % op)
171 f.writeln(" __pretty_assert_fail( \\")
172 f.writeln(" __FILE__, __LINE__, \\")
173 f.writeln(" __pretty_assert_print_mem, \"%s\", \\"
175 f.writeln(" _lh, size, \\")
176 f.writeln(" _rh, size); \\")
177 f.writeln(" } \\")
178 f.writeln("} while (0)")
180 f.writeln("#define __PRETTY_ASSERT_STR_%s(lh, rh) do { \\"
182 f.writeln(" const char *_lh = lh; \\")
183 f.writeln(" const char *_rh = rh; \\")
184 f.writeln(" if (!(strcmp(_lh, _rh) %s 0)) { \\" % op)
185 f.writeln(" __pretty_assert_fail( \\")
186 f.writeln(" __FILE__, __LINE__, \\")
187 f.writeln(" __pretty_assert_print_str, \"%s\", \\"
189 f.writeln(" _lh, strlen(_lh), \\")
190 f.writeln(" _rh, strlen(_rh)); \\")
191 f.writeln(" } \\")
192 f.writeln("} while (0)")
197 f.writeln("#define __PRETTY_ASSERT_PTR_%s(lh, rh) do { \\"
199 f.writeln(" const void *_lh = (const void*)(uintptr_t)lh; \\")
200 f.writeln(" const void *_rh = (const void*)(uintptr_t)rh; \\")
201 f.writeln(" if (!(_lh %s _rh)) { \\" % op)
202 f.writeln(" __pretty_assert_fail( \\")
203 f.writeln(" __FILE__, __LINE__, \\")
204 f.writeln(" __pretty_assert_print_ptr, \"%s\", \\"
206 f.writeln(" (const void*){_lh}, 0, \\")
207 f.writeln(" (const void*){_rh}, 0); \\")
208 f.writeln(" } \\")
209 f.writeln("} while (0)")
210 f.writeln()
211 f.writeln()
425 with openio(output or '-', 'w') as f:
427 f.write(s)
428 f.write('\n')
429 f.writeln = writeln
432 write_header(f, limit=limit)
434 f.writeln("#line %d \"%s\"" % (1, input))
439 f.write(p_stmt(p))
441 f.write(p.m)
449 f.write(p.tokens[i][1])