asar coverage - build #81


src/asar/
File: src/asar/macro.cpp
Date: 2024-01-19 05:09:49
Lines:
225/230
97.8%
Functions:
10/10
100.0%
Branches:
184/284
64.8%

Line Branch Exec Source
1 #include "asar.h"
2 #include "assembleblock.h"
3 #include "macro.h"
4 #include "asar_math.h"
5 #include "warnings.h"
6
7 assocarr<macrodata*> macros;
8 string defining_macro_name;
9 static macrodata * thisone;
10 static int numlines;
11
12 int calledmacros;
13 int reallycalledmacros;
14 int macrorecursion;
15 bool inmacro;
16 int numvarargs;
17
18 macrodata* current_macro;
19 const char* const* current_macro_args;
20 int current_macro_numargs;
21
22 140 void startmacro(const char * line_)
23 {
24 140 thisone= nullptr;
25
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 140 times.
140 if (!confirmqpar(line_)) asar_throw_error(0, error_type_block, error_id_broken_macro_declaration);
26 70 string line=line_;
27
1/2
✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
140 line.qnormalize();
28 70 char * startpar=(char *)strchr(line.data(), '(');
29
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 140 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
140 if (!startpar) asar_throw_error(0, error_type_block, error_id_broken_macro_declaration);
30 140 *startpar=0;
31
2/4
✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 140 times.
✗ Branch 3 not taken.
280 startpar++;
32
2/6
✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 140 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
140 if (!confirmname(line)) asar_throw_error(0, error_type_block, error_id_invalid_macro_name);
33 defining_macro_name=line;
34 140 char * endpar=startpar+strlen(startpar)-1;
35 //confirmqpar requires that all parentheses are matched, and a starting one exists, therefore it is harmless to not check for nullptrs
36
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 140 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
140 if (*endpar != ')') asar_throw_error(0, error_type_block, error_id_broken_macro_declaration);
37 140 *endpar=0;
38
2/2
✓ Branch 0 taken 778 times.
✓ Branch 1 taken 140 times.
918 for (int i=0;startpar[i];i++)
39 {
40 char c=startpar[i];
41
5/8
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 570 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 202 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
778 if (!is_ualnum(c)&& c!=','&& c!='.'&& c!=' ') asar_throw_error(0, error_type_block, error_id_broken_macro_declaration);
42
3/6
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 732 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 46 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
778 if (c==',' && is_digit(startpar[i+1])) asar_throw_error(0, error_type_block, error_id_broken_macro_declaration);
43 }
44
4/10
✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 140 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 140 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 140 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
140 if (*startpar==',' || is_digit(*startpar) || strstr(startpar, ",,") || endpar[-1]==',') asar_throw_error(0, error_type_block, error_id_broken_macro_declaration);
45
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 140 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
140 if (macros.exists(defining_macro_name)) asar_throw_error(0, error_type_block, error_id_macro_redefined, defining_macro_name.data());
46 140 thisone=(macrodata*)malloc(sizeof(macrodata));
47 new(thisone) macrodata;
48
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 46 times.
140 if (*startpar)
49 {
50
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 char **arguments = split(duplicate_string(startpar), ',', &thisone->numargs);
51 94 thisone->arguments_buffer = arguments[0];
52
2/2
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 94 times.
234 for (int i=0;arguments[i];i++)
53 {
54 140 arguments[i] = strip_whitespace(arguments[i]);
55 }
56 94 thisone->arguments=(const char* const*)arguments;
57 }
58 else
59 {
60 46 const char ** noargs=(const char**)malloc(sizeof(const char**));
61 46 *noargs=nullptr;
62 46 thisone->arguments=noargs;
63 46 thisone->arguments_buffer = nullptr;
64 46 thisone->numargs=0;
65 }
66 140 thisone->variadic = false;
67
1/2
✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
140 thisone->fname= duplicate_string(get_current_file_name());
68
1/2
✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
140 thisone->startline=get_current_line();
69 140 thisone->parent_macro=current_macro;
70 140 thisone->parent_macro_num_varargs=0;
71 // RPG Hacker: -1 to take the ... into account, which is also being counted.
72
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 88 times.
140 if (thisone->parent_macro != nullptr) thisone->parent_macro_num_varargs = current_macro_numargs-(current_macro->numargs-1);
73
2/2
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 138 times.
276 for (int i=0;thisone->arguments[i];i++)
74 {
75
4/4
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 86 times.
✓ Branch 2 taken 50 times.
✓ Branch 3 taken 2 times.
138 if(!strcmp(thisone->arguments[i], "...") && !thisone->arguments[i+1]) thisone->variadic = true;
76
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 86 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
88 else if(!strcmp(thisone->arguments[i], "...")) asar_throw_error(0, error_type_block, error_id_vararg_must_be_last);
77
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 86 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
86 else if(strchr(thisone->arguments[i], '.')) asar_throw_error(0, error_type_block, error_id_invalid_macro_param_name);
78
2/6
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 86 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
86 else if (!confirmname(thisone->arguments[i])) asar_throw_error(0, error_type_block, error_id_invalid_macro_param_name);
79
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 136 times.
186 for (int j=i+1;thisone->arguments[j];j++)
80 {
81
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
50 if (!strcmp(thisone->arguments[i], thisone->arguments[j])) asar_throw_error(0, error_type_block, error_id_macro_param_redefined, thisone->arguments[i]);
82 }
83 }
84 138 numlines=0;
85 140 }
86
87 822 void tomacro(const char * line)
88 {
89
1/2
✓ Branch 0 taken 822 times.
✗ Branch 1 not taken.
822 if (!thisone) return;
90 822 thisone->lines[numlines++]=line;
91 }
92
93 140 void endmacro(bool insert)
94 {
95
1/2
✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
140 if (!thisone) return;
96 140 thisone->numlines=numlines;
97
2/2
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 2 times.
140 if (insert) macros.create(defining_macro_name) = thisone;
98 else
99 {
100 2 freemacro(thisone);
101 2 thisone=nullptr;
102 }
103 }
104
105 #define cfree(x) free((void*)x)
106 140 void freemacro(macrodata* & macro)
107 {
108 140 macro->lines.~autoarray();
109 140 cfree(macro->fname);
110 140 cfree(macro->arguments_buffer);
111 140 cfree(macro->arguments);
112 140 cfree(macro);
113 140 }
114 #undef cfree
115
116
117 522 void callmacro(const char * data)
118 {
119 522 int prev_numvarargs = numvarargs;
120 macrodata * thismacro;
121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 522 times.
522 if (!confirmqpar(data)) asar_throw_error(0, error_type_block, error_id_broken_macro_usage);
122 261 string line=data;
123
1/2
✓ Branch 0 taken 522 times.
✗ Branch 1 not taken.
522 line.qnormalize();
124 261 char * startpar=(char *)strchr(line.data(), '(');
125
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 522 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
522 if (!startpar) asar_throw_error(0, error_type_block, error_id_broken_macro_usage);
126 522 *startpar=0;
127
1/2
✓ Branch 0 taken 522 times.
✗ Branch 1 not taken.
522 startpar++;
128
2/6
✓ Branch 0 taken 522 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 522 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
522 if (!confirmname(line)) asar_throw_error(0, error_type_block, error_id_broken_macro_usage);
129
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 522 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
522 if (!macros.exists(line)) asar_throw_error(0, error_type_block, error_id_macro_not_found, line.data());
130 522 thismacro = macros.find(line);
131 522 char * endpar=startpar+strlen(startpar)-1;
132 //confirmqpar requires that all parentheses are matched, and a starting one exists, therefore it is harmless to not check for nullptrs
133
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 522 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
522 if (*endpar != ')') asar_throw_error(0, error_type_block, error_id_broken_macro_usage);
134
2/2
✓ Branch 0 taken 402 times.
✓ Branch 1 taken 120 times.
522 *endpar=0;
135 autoptr<const char * const*> args;
136 522 int numargs=0;
137
2/2
✓ Branch 0 taken 402 times.
✓ Branch 1 taken 120 times.
522 if (*startpar) {
138
1/2
✓ Branch 0 taken 402 times.
✗ Branch 1 not taken.
402 args=(const char* const*)qpsplit(startpar, ',', &numargs);
139 // qpsplit returns a nullptr when the input is broken, e.g. closing paren before opening or whatnot
140
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 402 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
402 if(args == nullptr) asar_throw_error(0, error_type_block, error_id_broken_macro_usage);
141 }
142
3/6
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 390 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 132 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
522 if (numargs != thismacro->numargs && !thismacro->variadic) asar_throw_error(1, error_type_block, error_id_macro_wrong_num_params);
143 // RPG Hacker: -1, because the ... is also counted as an argument, yet we want it to be entirely optional.
144
4/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 510 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
522 if (numargs < thismacro->numargs - 1 && thismacro->variadic) asar_throw_error(1, error_type_block, error_id_macro_wrong_min_params);
145
146 510 macrorecursion++;
147 510 inmacro=true;
148 510 int old_calledmacros = calledmacros;
149 510 calledmacros = reallycalledmacros++;
150 510 int startif=numif;
151
152
2/2
✓ Branch 0 taken 882 times.
✓ Branch 1 taken 510 times.
1392 for (int i = 0; i < numargs; ++i)
153 {
154 // RPG Hacker: These casts make me feel very nasty.
155
1/2
✓ Branch 0 taken 882 times.
✗ Branch 1 not taken.
882 (*reinterpret_cast<autoptr<const char**>*>(&args))[i] = safedequote(strip_whitespace((char*)args[i]));
156 }
157
158 // RPG Hacker: -1 to take the ... into account, which is also being counted.
159
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 330 times.
510 if(thismacro->variadic) numvarargs = numargs-(thismacro->numargs-1);
160 330 else numvarargs = -1;
161
162 510 autoarray<int>* oldmacroposlabels = macroposlabels;
163 510 autoarray<int>* oldmacroneglabels = macroneglabels;
164 510 autoarray<string>* oldmacrosublabels = macrosublabels;
165
166 255 autoarray<int> newmacroposlabels;
167 255 autoarray<int> newmacroneglabels;
168 255 autoarray<string> newmacrosublabels;
169
170 510 macroposlabels = &newmacroposlabels;
171 510 macroneglabels = &newmacroneglabels;
172 510 macrosublabels = &newmacrosublabels;
173
174 510 macrodata* old_macro = current_macro;
175 510 const char* const* old_macro_args = current_macro_args;
176 510 int old_numargs = current_macro_numargs;
177 510 current_macro = thismacro;
178 510 current_macro_args = args;
179 510 current_macro_numargs = numargs;
180
181 255 callstack_push cs_push(callstack_entry_type::MACRO_CALL, data);
182
183 {
184 510 callstack_push cs_push(callstack_entry_type::FILE, thismacro->fname);
185
186
2/2
✓ Branch 0 taken 7020 times.
✓ Branch 1 taken 510 times.
7530 for (int i=0;i<thismacro->numlines;i++)
187 {
188
1/2
✓ Branch 0 taken 7020 times.
✗ Branch 1 not taken.
7020 bool was_loop_end = do_line_logic(thismacro->lines[i], thismacro->fname, thismacro->startline+i+1);
189
190
4/4
✓ Branch 0 taken 1122 times.
✓ Branch 1 taken 5898 times.
✓ Branch 2 taken 540 times.
✓ Branch 3 taken 582 times.
7020 if (was_loop_end && whilestatus[numif].cond)
191 // RPG Hacker: -1 to compensate for the i++, and another -1
192 // because ->lines doesn't include the macro header.
193 582 i = whilestatus[numif].startline - thismacro->startline - 2;
194 }
195 510 }
196
197 510 macroposlabels = oldmacroposlabels;
198 510 macroneglabels = oldmacroneglabels;
199 510 macrosublabels = oldmacrosublabels;
200
201 510 current_macro = old_macro;
202 510 current_macro_args = old_macro_args;
203 510 current_macro_numargs = old_numargs;
204
205 510 macrorecursion--;
206 510 inmacro = macrorecursion;
207 510 numvarargs = prev_numvarargs;
208 510 calledmacros = old_calledmacros;
209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 510 times.
510 if (numif!=startif)
210 {
211 numif=startif;
212 numtrue=startif;
213 asar_throw_error(0, error_type_block, error_id_unclosed_if);
214 }
215 534 }
216
217 56 string generate_macro_arg_string(const char* named_arg, int depth)
218 {
219 28 string ret="<";
220
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 56 times.
116 for (int i = 0; i < depth;++i)
221 {
222 60 ret += '^';
223 }
224 56 ret += named_arg;
225 56 ret += ">";
226 56 return ret;
227 }
228
229 42 string generate_macro_arg_string(int var_arg, int depth)
230 {
231 21 string ret="<";
232
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 42 times.
60 for (int i = 0; i < depth;++i)
233 {
234 18 ret += '^';
235 }
236 42 ret += dec(var_arg);
237 42 ret += ">";
238 42 return ret;
239 }
240
241 76 string generate_macro_hint_string(const char* named_arg, const macrodata* thismacro, int desired_depth, int current_depth=0)
242 {
243 // RPG Hacker: This only work when the incorrectly used parameter
244 // is inside the macro that is currently being defined. Not great,
245 // but still better than nothing.
246
4/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 24 times.
76 if (current_depth == 0 && thisone != nullptr)
247 {
248
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10 times.
30 for (int j=0;thisone->arguments[j];j++)
249 {
250
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
20 if (!strcmp(named_arg, thisone->arguments[j]))
251 {
252 1 string ret=" Did you mean: '";
253 2 ret += generate_macro_arg_string(thisone->arguments[j], 0);
254 2 ret += "'?";
255 1 return ret;
256 2 }
257 }
258 }
259
260 // RPG Hacker: Technically, we could skip a level here and go straight
261 // to the parent, but maybe at some point we'll want to expand this to
262 // also look for similar args in the current level, so I'll leave it
263 // like this, just in case.
264
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 16 times.
74 if (thismacro != nullptr)
265 {
266
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 40 times.
132 for (int j=0;thismacro->arguments[j];j++)
267 {
268
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 74 times.
92 if (!strcmp(named_arg, thismacro->arguments[j]))
269 {
270 9 string ret=" Did you mean: '";
271 18 ret += generate_macro_arg_string(thismacro->arguments[j], desired_depth+current_depth);
272 18 ret += "'?";
273 9 return ret;
274 18 }
275 }
276 40 return generate_macro_hint_string(named_arg, thismacro->parent_macro, desired_depth, current_depth+1);
277 }
278
279 8 return "";
280 }
281
282 42 string generate_macro_hint_string(int var_arg, const macrodata* thismacro, int desired_depth, int current_depth=0)
283 {
284
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 12 times.
42 if (thismacro != nullptr)
285 {
286
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 18 times.
30 if (thismacro->parent_macro_num_varargs > var_arg)
287 {
288 6 string ret=" Did you mean: '";
289 12 ret += generate_macro_arg_string(var_arg, desired_depth+current_depth+1);
290 12 ret += "'?";
291 6 return ret;
292 12 }
293 18 return generate_macro_hint_string(var_arg, thismacro->parent_macro, desired_depth, current_depth+1);
294 }
295
296 6 return "";
297 }
298
299 48708 string replace_macro_args(const char* line) {
300 22104 string out;
301
2/2
✓ Branch 0 taken 42660 times.
✓ Branch 1 taken 6048 times.
48708 if(!inmacro)
302 {
303 42660 out += line;
304 return out;
305 }
306
2/2
✓ Branch 0 taken 80184 times.
✓ Branch 1 taken 5946 times.
86130 for (const char * in=line;*in;)
307 {
308
5/6
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 77916 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 2250 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
80184 if (*in=='<' && in[1]=='<' && in[2] != ':')
309 {
310
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (in[2] == '^')
311 {
312 18 out+="<";
313 18 in+=1;
314 }
315 else
316 {
317 out+="<<";
318 in+=2;
319 }
320 }
321
2/2
✓ Branch 0 taken 2250 times.
✓ Branch 1 taken 77916 times.
80166 else if (*in=='<')
322 {
323 2250 const char * end=in+1;
324 // RPG Hacker: Added checking for space here, because this code would consider
325 // if a < b && a > c
326 // a macro arg expansion. In practice, this is still a sloppy solution and is
327 // likely to fail in some edge case I can't think of right now. Should parse
328 // this in a much more robust way at some point...
329
2/2
✓ Branch 0 taken 720 times.
✓ Branch 1 taken 1530 times.
2250 if (*end==' ')
330 {
331 720 out += *(in++);
332 1614 continue;
333 }
334
335
6/8
✓ Branch 0 taken 13284 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 11772 times.
✓ Branch 3 taken 1512 times.
✓ Branch 4 taken 11772 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11772 times.
✗ Branch 7 not taken.
13302 while (*end && *end!='>'&& *end!='<' && *(end+1)!=':') end++; //allow for conditionals and <:
336
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1512 times.
1530 if (*end!='>')
337 {
338 18 out+=*(in++);
339 18 continue;
340 }
341
342 int depth = 0;
343
2/2
✓ Branch 0 taken 186 times.
✓ Branch 1 taken 1512 times.
1698 for (const char* depth_str = in+1; *depth_str=='^'; depth_str++)
344 {
345 186 depth++;
346 }
347
348
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 1350 times.
1512 if (depth != in_macro_def)
349 {
350 162 string temp(in, end-in+1);
351 162 out+=temp;
352 162 in=end+1;
353
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 144 times.
162 if (depth > in_macro_def)
354 {
355
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
18 if (in_macro_def > 0) asar_throw_error(0, error_type_line, error_id_invalid_depth_resolve, "macro parameter", "macro parameter", depth, in_macro_def-1);
356 //else asar_throw_error(0, error_type_block, error_id_macro_param_outside_macro);
357 }
358 continue;
359 162 }
360
361
3/6
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 1218 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 132 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1350 if (depth > 0 && !inmacro) asar_throw_error(0, error_type_line, error_id_invalid_depth_resolve, "macro parameter", "macro parameter", depth, in_macro_def-1);
362 1350 in += depth+1;
363
364 bool is_variadic_arg = false;
365
5/8
✓ Branch 0 taken 630 times.
✓ Branch 1 taken 720 times.
✓ Branch 2 taken 630 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 630 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 630 times.
✗ Branch 7 not taken.
1350 if (in[0] == '.' && in[1] == '.' && in[2] == '.' && in[3] == '[')
366 {
367
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 624 times.
630 if (end[-1] != ']')
368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 asar_throw_error(0, error_type_block, error_id_unclosed_vararg);
369
370 is_variadic_arg = true;
371 624 in += 4;
372 624 end--;
373 }
374
375 //if(!inmacro) asar_throw_error(0, error_type_block, error_id_macro_param_outside_macro);
376
5/6
✓ Branch 0 taken 624 times.
✓ Branch 1 taken 720 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 618 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
1344 if(is_variadic_arg && !current_macro->variadic) asar_throw_error(0, error_type_block, error_id_macro_not_varadic, "<...[math]>");
377 //*end=0;
378 669 string param;
379 1338 string temp(in, end-in);
380
1/2
✓ Branch 0 taken 1338 times.
✗ Branch 1 not taken.
1338 resolvedefines(param, temp);
381 in = param.data();
382
1/2
✓ Branch 0 taken 1338 times.
✗ Branch 1 not taken.
1338 bool valid_named_param = confirmname(in);
383
2/2
✓ Branch 0 taken 720 times.
✓ Branch 1 taken 618 times.
1338 if (!is_variadic_arg)
384 {
385
3/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 708 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
720 if (!valid_named_param) asar_throw_error(0, error_type_block, error_id_invalid_macro_param_name);
386 bool found=false;
387
2/2
✓ Branch 0 taken 888 times.
✓ Branch 1 taken 36 times.
924 for (int j=0;current_macro->arguments[j];j++)
388 {
389
2/2
✓ Branch 0 taken 672 times.
✓ Branch 1 taken 216 times.
888 if (!strcmp(in, current_macro->arguments[j]))
390 {
391 found=true;
392 672 out+=current_macro_args[j];
393 break;
394 }
395 }
396 if (!found)
397 {
398
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
72 asar_throw_error(0, error_type_block, error_id_macro_param_not_found, generate_macro_arg_string(in, depth).raw(), generate_macro_hint_string(in, current_macro, depth).raw());
399 }
400 }
401 else
402 {
403 309 snes_label ret;
404
8/10
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 606 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 612 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
630 if(valid_named_param && !labelval(in, &ret, false)) asar_throw_error(0, error_type_block, error_id_invalid_vararg, in);
405
1/2
✓ Branch 0 taken 612 times.
✗ Branch 1 not taken.
612 int arg_num = getnum(in);
406
407
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 612 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
612 if(forwardlabel) asar_throw_error(0, error_type_block, error_id_label_forward);
408
409
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 606 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
612 if (arg_num < 0) asar_throw_error(1, error_type_block, error_id_vararg_out_of_bounds, generate_macro_arg_string(arg_num, depth).raw(), "");
410
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 582 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
630 if (arg_num > current_macro_numargs-current_macro->numargs) asar_throw_error(1, error_type_block, error_id_vararg_out_of_bounds, generate_macro_arg_string(arg_num, depth).raw(), generate_macro_hint_string(arg_num, current_macro, depth).raw());
411 582 out+=current_macro_args[arg_num+current_macro->numargs-1];
412 }
413 1254 in=end+1;
414
2/2
✓ Branch 0 taken 582 times.
✓ Branch 1 taken 672 times.
1254 if (is_variadic_arg) in++;
415 1422 }
416 77916 else out+=*(in++);
417 }
418 return out;
419 102 }
420