| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#include "litavis.h" |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
/* Store C context pointer inside Perl object */ |
|
4
|
|
|
|
|
|
|
typedef LitavisCtx* Litavis; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
MODULE = Litavis PACKAGE = Litavis |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Litavis |
|
9
|
|
|
|
|
|
|
new(class, ...) |
|
10
|
|
|
|
|
|
|
const char *class |
|
11
|
|
|
|
|
|
|
PREINIT: |
|
12
|
|
|
|
|
|
|
LitavisCtx *ctx; |
|
13
|
|
|
|
|
|
|
int i; |
|
14
|
|
|
|
|
|
|
CODE: |
|
15
|
312
|
|
|
|
|
|
ctx = litavis_ctx_new(); |
|
16
|
|
|
|
|
|
|
/* Parse optional hash-style args from Perl stack */ |
|
17
|
312
|
100
|
|
|
|
|
if (items > 1 && (items - 1) % 2 == 0) { |
|
|
|
50
|
|
|
|
|
|
|
18
|
170
|
100
|
|
|
|
|
for (i = 1; i < items; i += 2) { |
|
19
|
98
|
|
|
|
|
|
const char *key = SvPV_nolen(ST(i)); |
|
20
|
98
|
100
|
|
|
|
|
if (strcmp(key, "pretty") == 0) { |
|
21
|
19
|
|
|
|
|
|
ctx->pretty = SvIV(ST(i + 1)); |
|
22
|
79
|
100
|
|
|
|
|
} else if (strcmp(key, "dedupe") == 0) { |
|
23
|
48
|
|
|
|
|
|
ctx->dedupe = SvIV(ST(i + 1)); |
|
24
|
31
|
100
|
|
|
|
|
} else if (strcmp(key, "indent") == 0) { |
|
25
|
4
|
50
|
|
|
|
|
if (ctx->indent) free(ctx->indent); |
|
26
|
4
|
|
|
|
|
|
ctx->indent = litavis_strdup(SvPV_nolen(ST(i + 1))); |
|
27
|
27
|
100
|
|
|
|
|
} else if (strcmp(key, "shorthand_hex") == 0) { |
|
28
|
13
|
|
|
|
|
|
ctx->shorthand_hex = SvIV(ST(i + 1)); |
|
29
|
14
|
50
|
|
|
|
|
} else if (strcmp(key, "sort_props") == 0) { |
|
30
|
14
|
|
|
|
|
|
ctx->sort_props = SvIV(ST(i + 1)); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
} |
|
34
|
312
|
|
|
|
|
|
RETVAL = ctx; |
|
35
|
|
|
|
|
|
|
OUTPUT: |
|
36
|
|
|
|
|
|
|
RETVAL |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
void |
|
39
|
|
|
|
|
|
|
DESTROY(self) |
|
40
|
|
|
|
|
|
|
Litavis self |
|
41
|
|
|
|
|
|
|
CODE: |
|
42
|
312
|
|
|
|
|
|
litavis_ctx_free(self); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
SV* |
|
45
|
|
|
|
|
|
|
parse(self, input) |
|
46
|
|
|
|
|
|
|
Litavis self |
|
47
|
|
|
|
|
|
|
const char *input |
|
48
|
|
|
|
|
|
|
CODE: |
|
49
|
561
|
|
|
|
|
|
litavis_parse_string(self, input); |
|
50
|
|
|
|
|
|
|
/* return self for chaining */ |
|
51
|
561
|
|
|
|
|
|
RETVAL = SvREFCNT_inc(ST(0)); |
|
52
|
|
|
|
|
|
|
OUTPUT: |
|
53
|
|
|
|
|
|
|
RETVAL |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
SV* |
|
56
|
|
|
|
|
|
|
parse_file(self, filename) |
|
57
|
|
|
|
|
|
|
Litavis self |
|
58
|
|
|
|
|
|
|
const char *filename |
|
59
|
|
|
|
|
|
|
CODE: |
|
60
|
5
|
|
|
|
|
|
litavis_parse_file(self, filename); |
|
61
|
4
|
|
|
|
|
|
RETVAL = SvREFCNT_inc(ST(0)); |
|
62
|
|
|
|
|
|
|
OUTPUT: |
|
63
|
|
|
|
|
|
|
RETVAL |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
SV* |
|
66
|
|
|
|
|
|
|
parse_dir(self, dirname) |
|
67
|
|
|
|
|
|
|
Litavis self |
|
68
|
|
|
|
|
|
|
const char *dirname |
|
69
|
|
|
|
|
|
|
CODE: |
|
70
|
16
|
|
|
|
|
|
litavis_parse_dir(self, dirname); |
|
71
|
15
|
|
|
|
|
|
RETVAL = SvREFCNT_inc(ST(0)); |
|
72
|
|
|
|
|
|
|
OUTPUT: |
|
73
|
|
|
|
|
|
|
RETVAL |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
SV* |
|
76
|
|
|
|
|
|
|
compile(self) |
|
77
|
|
|
|
|
|
|
Litavis self |
|
78
|
|
|
|
|
|
|
CODE: |
|
79
|
175
|
|
|
|
|
|
char *css = litavis_emit(self); |
|
80
|
175
|
|
|
|
|
|
RETVAL = newSVpv(css, 0); |
|
81
|
175
|
|
|
|
|
|
free(css); |
|
82
|
|
|
|
|
|
|
OUTPUT: |
|
83
|
|
|
|
|
|
|
RETVAL |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
void |
|
86
|
|
|
|
|
|
|
compile_file(self, filename) |
|
87
|
|
|
|
|
|
|
Litavis self |
|
88
|
|
|
|
|
|
|
const char *filename |
|
89
|
|
|
|
|
|
|
CODE: |
|
90
|
2
|
|
|
|
|
|
litavis_emit_file(self, filename); |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
void |
|
93
|
|
|
|
|
|
|
reset(self) |
|
94
|
|
|
|
|
|
|
Litavis self |
|
95
|
|
|
|
|
|
|
CODE: |
|
96
|
9
|
|
|
|
|
|
litavis_ctx_reset(self); |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
int |
|
99
|
|
|
|
|
|
|
pretty(self, ...) |
|
100
|
|
|
|
|
|
|
Litavis self |
|
101
|
|
|
|
|
|
|
CODE: |
|
102
|
5
|
100
|
|
|
|
|
if (items > 1) |
|
103
|
3
|
|
|
|
|
|
self->pretty = SvIV(ST(1)); |
|
104
|
5
|
50
|
|
|
|
|
RETVAL = self->pretty; |
|
105
|
|
|
|
|
|
|
OUTPUT: |
|
106
|
|
|
|
|
|
|
RETVAL |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
int |
|
109
|
|
|
|
|
|
|
dedupe(self, ...) |
|
110
|
|
|
|
|
|
|
Litavis self |
|
111
|
|
|
|
|
|
|
CODE: |
|
112
|
5
|
100
|
|
|
|
|
if (items > 1) |
|
113
|
3
|
|
|
|
|
|
self->dedupe = SvIV(ST(1)); |
|
114
|
5
|
50
|
|
|
|
|
RETVAL = self->dedupe; |
|
115
|
|
|
|
|
|
|
OUTPUT: |
|
116
|
|
|
|
|
|
|
RETVAL |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# ── AST introspection (for testing and debugging) ────────── |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
void |
|
121
|
|
|
|
|
|
|
_ast_add_rule(self, selector) |
|
122
|
|
|
|
|
|
|
Litavis self |
|
123
|
|
|
|
|
|
|
const char *selector |
|
124
|
|
|
|
|
|
|
CODE: |
|
125
|
212
|
|
|
|
|
|
litavis_ast_add_rule(self->ast, selector); |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
int |
|
128
|
|
|
|
|
|
|
_ast_has_rule(self, selector) |
|
129
|
|
|
|
|
|
|
Litavis self |
|
130
|
|
|
|
|
|
|
const char *selector |
|
131
|
|
|
|
|
|
|
CODE: |
|
132
|
38
|
|
|
|
|
|
RETVAL = litavis_ast_has_rule(self->ast, selector); |
|
133
|
|
|
|
|
|
|
OUTPUT: |
|
134
|
|
|
|
|
|
|
RETVAL |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
int |
|
137
|
|
|
|
|
|
|
_ast_rule_count(self) |
|
138
|
|
|
|
|
|
|
Litavis self |
|
139
|
|
|
|
|
|
|
CODE: |
|
140
|
46
|
50
|
|
|
|
|
RETVAL = self->ast->count; |
|
141
|
|
|
|
|
|
|
OUTPUT: |
|
142
|
|
|
|
|
|
|
RETVAL |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
SV* |
|
145
|
|
|
|
|
|
|
_ast_rule_selector(self, index) |
|
146
|
|
|
|
|
|
|
Litavis self |
|
147
|
|
|
|
|
|
|
int index |
|
148
|
|
|
|
|
|
|
CODE: |
|
149
|
37
|
100
|
|
|
|
|
if (index < 0 || index >= self->ast->count) |
|
|
|
100
|
|
|
|
|
|
|
150
|
2
|
|
|
|
|
|
XSRETURN_UNDEF; |
|
151
|
35
|
|
|
|
|
|
RETVAL = newSVpv(self->ast->rules[index].selector, 0); |
|
152
|
|
|
|
|
|
|
OUTPUT: |
|
153
|
|
|
|
|
|
|
RETVAL |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
void |
|
156
|
|
|
|
|
|
|
_ast_remove_rule(self, index) |
|
157
|
|
|
|
|
|
|
Litavis self |
|
158
|
|
|
|
|
|
|
int index |
|
159
|
|
|
|
|
|
|
CODE: |
|
160
|
1
|
|
|
|
|
|
litavis_ast_remove_rule(self->ast, index); |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
void |
|
163
|
|
|
|
|
|
|
_ast_rename_rule(self, index, new_selector) |
|
164
|
|
|
|
|
|
|
Litavis self |
|
165
|
|
|
|
|
|
|
int index |
|
166
|
|
|
|
|
|
|
const char *new_selector |
|
167
|
|
|
|
|
|
|
CODE: |
|
168
|
1
|
|
|
|
|
|
litavis_ast_rename_rule(self->ast, index, new_selector); |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
void |
|
171
|
|
|
|
|
|
|
_ast_add_prop(self, selector, key, value) |
|
172
|
|
|
|
|
|
|
Litavis self |
|
173
|
|
|
|
|
|
|
const char *selector |
|
174
|
|
|
|
|
|
|
const char *key |
|
175
|
|
|
|
|
|
|
const char *value |
|
176
|
|
|
|
|
|
|
CODE: |
|
177
|
11
|
|
|
|
|
|
LitavisRule *rule = litavis_ast_get_rule(self->ast, selector); |
|
178
|
11
|
100
|
|
|
|
|
if (!rule) |
|
179
|
1
|
|
|
|
|
|
croak("litavis: no rule with selector '%s'", selector); |
|
180
|
10
|
|
|
|
|
|
litavis_rule_add_prop(rule, key, value); |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
SV* |
|
183
|
|
|
|
|
|
|
_ast_get_prop(self, selector, key) |
|
184
|
|
|
|
|
|
|
Litavis self |
|
185
|
|
|
|
|
|
|
const char *selector |
|
186
|
|
|
|
|
|
|
const char *key |
|
187
|
|
|
|
|
|
|
CODE: |
|
188
|
133
|
|
|
|
|
|
LitavisRule *rule = litavis_ast_get_rule(self->ast, selector); |
|
189
|
133
|
100
|
|
|
|
|
if (!rule) |
|
190
|
1
|
|
|
|
|
|
XSRETURN_UNDEF; |
|
191
|
132
|
|
|
|
|
|
char *val = litavis_rule_get_prop(rule, key); |
|
192
|
132
|
100
|
|
|
|
|
if (!val) |
|
193
|
1
|
|
|
|
|
|
XSRETURN_UNDEF; |
|
194
|
131
|
|
|
|
|
|
RETVAL = newSVpv(val, 0); |
|
195
|
|
|
|
|
|
|
OUTPUT: |
|
196
|
|
|
|
|
|
|
RETVAL |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
int |
|
199
|
|
|
|
|
|
|
_ast_has_prop(self, selector, key) |
|
200
|
|
|
|
|
|
|
Litavis self |
|
201
|
|
|
|
|
|
|
const char *selector |
|
202
|
|
|
|
|
|
|
const char *key |
|
203
|
|
|
|
|
|
|
CODE: |
|
204
|
4
|
|
|
|
|
|
LitavisRule *rule = litavis_ast_get_rule(self->ast, selector); |
|
205
|
4
|
100
|
|
|
|
|
if (!rule) |
|
206
|
1
|
|
|
|
|
|
RETVAL = 0; |
|
207
|
|
|
|
|
|
|
else |
|
208
|
3
|
|
|
|
|
|
RETVAL = litavis_rule_has_prop(rule, key); |
|
209
|
|
|
|
|
|
|
OUTPUT: |
|
210
|
|
|
|
|
|
|
RETVAL |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
int |
|
213
|
|
|
|
|
|
|
_ast_prop_count(self, selector) |
|
214
|
|
|
|
|
|
|
Litavis self |
|
215
|
|
|
|
|
|
|
const char *selector |
|
216
|
|
|
|
|
|
|
CODE: |
|
217
|
4
|
|
|
|
|
|
LitavisRule *rule = litavis_ast_get_rule(self->ast, selector); |
|
218
|
4
|
100
|
|
|
|
|
if (!rule) |
|
219
|
1
|
|
|
|
|
|
RETVAL = 0; |
|
220
|
|
|
|
|
|
|
else |
|
221
|
3
|
|
|
|
|
|
RETVAL = rule->prop_count; |
|
222
|
|
|
|
|
|
|
OUTPUT: |
|
223
|
|
|
|
|
|
|
RETVAL |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
int |
|
226
|
|
|
|
|
|
|
_ast_rules_props_equal(self, sel_a, sel_b) |
|
227
|
|
|
|
|
|
|
Litavis self |
|
228
|
|
|
|
|
|
|
const char *sel_a |
|
229
|
|
|
|
|
|
|
const char *sel_b |
|
230
|
|
|
|
|
|
|
CODE: |
|
231
|
5
|
|
|
|
|
|
LitavisRule *a = litavis_ast_get_rule(self->ast, sel_a); |
|
232
|
5
|
|
|
|
|
|
LitavisRule *b = litavis_ast_get_rule(self->ast, sel_b); |
|
233
|
5
|
100
|
|
|
|
|
if (!a || !b) |
|
|
|
100
|
|
|
|
|
|
|
234
|
3
|
|
|
|
|
|
RETVAL = 0; |
|
235
|
|
|
|
|
|
|
else |
|
236
|
2
|
|
|
|
|
|
RETVAL = litavis_rules_props_equal(a, b); |
|
237
|
|
|
|
|
|
|
OUTPUT: |
|
238
|
|
|
|
|
|
|
RETVAL |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
void |
|
241
|
|
|
|
|
|
|
_ast_merge_props(self, dst_sel, src_sel) |
|
242
|
|
|
|
|
|
|
Litavis self |
|
243
|
|
|
|
|
|
|
const char *dst_sel |
|
244
|
|
|
|
|
|
|
const char *src_sel |
|
245
|
|
|
|
|
|
|
CODE: |
|
246
|
4
|
|
|
|
|
|
LitavisRule *dst = litavis_ast_get_rule(self->ast, dst_sel); |
|
247
|
4
|
|
|
|
|
|
LitavisRule *src = litavis_ast_get_rule(self->ast, src_sel); |
|
248
|
4
|
100
|
|
|
|
|
if (!dst || !src) |
|
|
|
100
|
|
|
|
|
|
|
249
|
3
|
|
|
|
|
|
croak("litavis: rule not found for merge"); |
|
250
|
1
|
|
|
|
|
|
litavis_rule_merge_props(dst, src); |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
void |
|
253
|
|
|
|
|
|
|
_dedupe(self, strategy) |
|
254
|
|
|
|
|
|
|
Litavis self |
|
255
|
|
|
|
|
|
|
int strategy |
|
256
|
|
|
|
|
|
|
CODE: |
|
257
|
32
|
|
|
|
|
|
litavis_dedupe(self->ast, (LitavisDedupeStrategy)strategy); |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
void |
|
260
|
|
|
|
|
|
|
_resolve_vars(self) |
|
261
|
|
|
|
|
|
|
Litavis self |
|
262
|
|
|
|
|
|
|
CODE: |
|
263
|
34
|
|
|
|
|
|
litavis_resolve_vars(self->ast, self->global_scope, self->mixins, self->maps); |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
void |
|
266
|
|
|
|
|
|
|
_resolve_colours(self) |
|
267
|
|
|
|
|
|
|
Litavis self |
|
268
|
|
|
|
|
|
|
CODE: |
|
269
|
42
|
|
|
|
|
|
litavis_resolve_colours(self->ast); |