asar coverage - build #85


src/asar/
File: src/asar/macro.cpp
Date: 2024-01-19 08:31:09
Lines:
225/230
97.8%
Functions:
10/10
100.0%
Branches:
196/303
64.7%

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 420 void startmacro(const char * line_)
23 {
24 420 thisone= nullptr;
25
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 420 times.
420 if (!confirmqpar(line_)) asar_throw_error(0, error_type_block, error_id_broken_macro_declaration);
26 210 string line=line_;
27
1/2
✓ Branch 0 taken 420 times.
✗ Branch 1 not taken.
420 line.qnormalize();
28 210 char * startpar=(char *)strchr(line.data(), '(');
29
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 420 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
420 if (!startpar) asar_throw_error(0, error_type_block, error_id_broken_macro_declaration);
30 420 *startpar=0;
31
2/4
✓ Branch 0 taken 420 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 420 times.
✗ Branch 3 not taken.
840 startpar++;
32
2/6
✓ Branch 0 taken 420 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 420 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
420 if (!confirmname(line)) asar_throw_error(0, error_type_block, error_id_invalid_macro_name);
33 defining_macro_name=line;
34 420 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 420 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
420 if (*endpar != ')') asar_throw_error(0, error_type_block, error_id_broken_macro_declaration);
37 420 *endpar=0;
38
2/2
✓ Branch 0 taken 2334 times.
✓ Branch 1 taken 420 times.
2754 for (int i=0;startpar[i];i++)
39 {
40 char c=startpar[i];
41
5/8
✓ Branch 0 taken 624 times.
✓ Branch 1 taken 1710 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 606 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2334 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 138 times.
✓ Branch 1 taken 2196 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 138 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2334 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 420 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 420 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 420 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 420 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
420 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 420 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
420 if (macros.exists(defining_macro_name)) asar_throw_error(0, error_type_block, error_id_macro_redefined, defining_macro_name.data());
46 420 thisone=(macrodata*)malloc(sizeof(macrodata));
47 new(thisone) macrodata;
48
2/2
✓ Branch 0 taken 282 times.
✓ Branch 1 taken 138 times.
420 if (*startpar)
49 {
50
1/2
✓ Branch 0 taken 282 times.
✗ Branch 1 not taken.
282 char **arguments = split(duplicate_string(startpar), ',', &thisone->numargs);
51 282 thisone->arguments_buffer = arguments[0];
52
2/2
✓ Branch 0 taken 420 times.
✓ Branch 1 taken 282 times.
702 for (int i=0;arguments[i];i++)
53 {
54 420 arguments[i] = strip_whitespace(arguments[i]);
55 }
56 282 thisone->arguments=(const char* const*)arguments;
57 }
58 else
59 {
60 138 const char ** noargs=(const char**)malloc(sizeof(const char**));
61 138 *noargs=nullptr;
62 138 thisone->arguments=noargs;
63 138 thisone->arguments_buffer = nullptr;
64 138 thisone->numargs=0;
65 }
66 420 thisone->variadic = false;
67
1/2
✓ Branch 0 taken 420 times.
✗ Branch 1 not taken.
420 thisone->fname= duplicate_string(get_current_file_name());
68
1/2
✓ Branch 0 taken 420 times.
✗ Branch 1 not taken.
420 thisone->startline=get_current_line();
69 420 thisone->parent_macro=current_macro;
70 420 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 156 times.
✓ Branch 1 taken 264 times.
420 if (thisone->parent_macro != nullptr) thisone->parent_macro_num_varargs = current_macro_numargs-(current_macro->numargs-1);
73
2/2
✓ Branch 0 taken 414 times.
✓ Branch 1 taken 414 times.
828 for (int i=0;thisone->arguments[i];i++)
74 {
75
4/4
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 258 times.
✓ Branch 2 taken 150 times.
✓ Branch 3 taken 6 times.
414 if(!strcmp(thisone->arguments[i], "...") && !thisone->arguments[i+1]) thisone->variadic = true;
76
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
264 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 258 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258 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 258 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 258 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
258 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 150 times.
✓ Branch 1 taken 408 times.
558 for (int j=i+1;thisone->arguments[j];j++)
80 {
81
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 150 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
150 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 414 numlines=0;
85 420 }
86
87 2466 void tomacro(const char * line)
88 {
89
1/2
✓ Branch 0 taken 2466 times.
✗ Branch 1 not taken.
2466 if (!thisone) return;
90 2466 thisone->lines[numlines++]=line;
91 }
92
93 420 void endmacro(bool insert)
94 {
95
1/2
✓ Branch 0 taken 420 times.
✗ Branch 1 not taken.
420 if (!thisone) return;
96 420 thisone->numlines=numlines;
97
2/2
✓ Branch 0 taken 414 times.
✓ Branch 1 taken 6 times.
420 if (insert) macros.create(defining_macro_name) = thisone;
98 else
99 {
100 6 freemacro(thisone);
101 6 thisone=nullptr;
102 }
103 }
104
105 #define cfree(x) free((void*)x)
106 420 void freemacro(macrodata* & macro)
107 {
108 420 macro->lines.~autoarray();
109 420 cfree(macro->fname);
110 420 cfree(macro->arguments_buffer);
111 420 cfree(macro->arguments);
112 420 cfree(macro);
113 420 }
114 #undef cfree
115
116
117 1566 void callmacro(const char * data)
118 {
119 1566 int prev_numvarargs = numvarargs;
120 macrodata * thismacro;
121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1566 times.
1566 if (!confirmqpar(data)) asar_throw_error(0, error_type_block, error_id_broken_macro_usage);
122 783 string line=data;
123
1/2
✓ Branch 0 taken 1566 times.
✗ Branch 1 not taken.
1566 line.qnormalize();
124 783 char * startpar=(char *)strchr(line.data(), '(');
125
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1566 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1566 if (!startpar) asar_throw_error(0, error_type_block, error_id_broken_macro_usage);
126 1566 *startpar=0;
127
1/2
✓ Branch 0 taken 1566 times.
✗ Branch 1 not taken.
1566 startpar++;
128
2/6
✓ Branch 0 taken 1566 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1566 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1566 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 1566 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1566 if (!macros.exists(line)) asar_throw_error(0, error_type_block, error_id_macro_not_found, line.data());
130 1566 thismacro = macros.find(line);
131 1566 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 1566 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1566 if (*endpar != ')') asar_throw_error(0, error_type_block, error_id_broken_macro_usage);
134
2/2
✓ Branch 0 taken 1206 times.
✓ Branch 1 taken 360 times.
1566 *endpar=0;
135 autoptr<const char * const*> args;
136 1566 int numargs=0;
137
2/2
✓ Branch 0 taken 1206 times.
✓ Branch 1 taken 360 times.
1566 if (*startpar) {
138
1/2
✓ Branch 0 taken 1206 times.
✗ Branch 1 not taken.
1206 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 1206 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1206 if(args == nullptr) asar_throw_error(0, error_type_block, error_id_broken_macro_usage);
141 }
142
3/6
✓ Branch 0 taken 396 times.
✓ Branch 1 taken 1170 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 396 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1566 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 36 times.
✓ Branch 1 taken 1530 times.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 36 times.
1566 if (numargs < thismacro->numargs - 1 && thismacro->variadic) asar_throw_error(1, error_type_block, error_id_macro_wrong_min_params);
145
146 1530 macrorecursion++;
147 1530 inmacro=true;
148 1530 int old_calledmacros = calledmacros;
149 1530 calledmacros = reallycalledmacros++;
150 1530 int startif=numif;
151
152
2/2
✓ Branch 0 taken 2646 times.
✓ Branch 1 taken 1530 times.
4176 for (int i = 0; i < numargs; ++i)
153 {
154 // RPG Hacker: These casts make me feel very nasty.
155
1/2
✓ Branch 0 taken 2646 times.
✗ Branch 1 not taken.
2646 (*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 540 times.
✓ Branch 1 taken 990 times.
1530 if(thismacro->variadic) numvarargs = numargs-(thismacro->numargs-1);
160 990 else numvarargs = -1;
161
162 1530 autoarray<int>* oldmacroposlabels = macroposlabels;
163 1530 autoarray<int>* oldmacroneglabels = macroneglabels;
164 1530 autoarray<string>* oldmacrosublabels = macrosublabels;
165
166 765 autoarray<int> newmacroposlabels;
167 765 autoarray<int> newmacroneglabels;
168 765 autoarray<string> newmacrosublabels;
169
170 1530 macroposlabels = &newmacroposlabels;
171 1530 macroneglabels = &newmacroneglabels;
172 1530 macrosublabels = &newmacrosublabels;
173
174 1530 macrodata* old_macro = current_macro;
175 1530 const char* const* old_macro_args = current_macro_args;
176 1530 int old_numargs = current_macro_numargs;
177 1530 current_macro = thismacro;
178 1530 current_macro_args = args;
179 1530 current_macro_numargs = numargs;
180
181 765 callstack_push cs_push(callstack_entry_type::MACRO_CALL, data);
182
183 {
184 1530 callstack_push cs_push(callstack_entry_type::FILE, thismacro->fname);
185
186
2/2
✓ Branch 0 taken 21072 times.
✓ Branch 1 taken 1530 times.
22602 for (int i=0;i<thismacro->numlines;i++)
187 {
188
1/2
✓ Branch 0 taken 21072 times.
✗ Branch 1 not taken.
21072 bool was_loop_end = do_line_logic(thismacro->lines[i], thismacro->fname, thismacro->startline+i+1);
189
190
4/4
✓ Branch 0 taken 3562 times.
✓ Branch 1 taken 17510 times.
✓ Branch 2 taken 1816 times.
✓ Branch 3 taken 1746 times.
21072 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 1746 i = whilestatus[numif].startline - thismacro->startline - 2;
194 }
195 1530 }
196
197 1530 macroposlabels = oldmacroposlabels;
198 1530 macroneglabels = oldmacroneglabels;
199 1530 macrosublabels = oldmacrosublabels;
200
201 1530 current_macro = old_macro;
202 1530 current_macro_args = old_macro_args;
203 1530 current_macro_numargs = old_numargs;
204
205 1530 macrorecursion--;
206 1530 inmacro = macrorecursion;
207 1530 numvarargs = prev_numvarargs;
208 1530 calledmacros = old_calledmacros;
209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1530 times.
1530 if (numif!=startif)
210 {
211 numif=startif;
212 numtrue=startif;
213 asar_throw_error(0, error_type_block, error_id_unclosed_if);
214 }
215 1602 }
216
217 168 string generate_macro_arg_string(const char* named_arg, int depth)
218 {
219 84 string ret="<";
220
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 168 times.
348 for (int i = 0; i < depth;++i)
221 {
222 180 ret += '^';
223 }
224 168 ret += named_arg;
225 168 ret += ">";
226 168 return ret;
227 }
228
229 126 string generate_macro_arg_string(int var_arg, int depth)
230 {
231 63 string ret="<";
232
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 126 times.
180 for (int i = 0; i < depth;++i)
233 {
234 54 ret += '^';
235 }
236 126 ret += dec(var_arg);
237 126 ret += ">";
238 126 return ret;
239 }
240
241 228 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 108 times.
✓ Branch 1 taken 120 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 72 times.
228 if (current_depth == 0 && thisone != nullptr)
247 {
248
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 30 times.
90 for (int j=0;thisone->arguments[j];j++)
249 {
250
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 54 times.
60 if (!strcmp(named_arg, thisone->arguments[j]))
251 {
252 3 string ret=" Did you mean: '";
253
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
6 ret += generate_macro_arg_string(thisone->arguments[j], 0);
254 6 ret += "'?";
255 3 return ret;
256 6 }
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 174 times.
✓ Branch 1 taken 48 times.
222 if (thismacro != nullptr)
265 {
266
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 120 times.
396 for (int j=0;thismacro->arguments[j];j++)
267 {
268
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 222 times.
276 if (!strcmp(named_arg, thismacro->arguments[j]))
269 {
270 27 string ret=" Did you mean: '";
271
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
54 ret += generate_macro_arg_string(thismacro->arguments[j], desired_depth+current_depth);
272 54 ret += "'?";
273 27 return ret;
274 54 }
275 }
276 120 return generate_macro_hint_string(named_arg, thismacro->parent_macro, desired_depth, current_depth+1);
277 }
278
279 24 return "";
280 }
281
282 126 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 90 times.
✓ Branch 1 taken 36 times.
126 if (thismacro != nullptr)
285 {
286
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 54 times.
90 if (thismacro->parent_macro_num_varargs > var_arg)
287 {
288 18 string ret=" Did you mean: '";
289
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
36 ret += generate_macro_arg_string(var_arg, desired_depth+current_depth+1);
290 36 ret += "'?";
291 18 return ret;
292 36 }
293 54 return generate_macro_hint_string(var_arg, thismacro->parent_macro, desired_depth, current_depth+1);
294 }
295
296 18 return "";
297 }
298
299 146013 string replace_macro_args(const char* line) {
300 66336 string out;
301
2/2
✓ Branch 0 taken 127857 times.
✓ Branch 1 taken 18156 times.
146013 if(!inmacro)
302 {
303 127857 out += line;
304 return out;
305 }
306
2/2
✓ Branch 0 taken 240552 times.
✓ Branch 1 taken 17850 times.
258402 for (const char * in=line;*in;)
307 {
308
5/6
✓ Branch 0 taken 6804 times.
✓ Branch 1 taken 233748 times.
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 6750 times.
✓ Branch 4 taken 54 times.
✗ Branch 5 not taken.
240552 if (*in=='<' && in[1]=='<' && in[2] != ':')
309 {
310
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if (in[2] == '^')
311 {
312 54 out+="<";
313 54 in+=1;
314 }
315 else
316 {
317 out+="<<";
318 in+=2;
319 }
320 }
321
2/2
✓ Branch 0 taken 6750 times.
✓ Branch 1 taken 233748 times.
240498 else if (*in=='<')
322 {
323 6750 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 2160 times.
✓ Branch 1 taken 4590 times.
6750 if (*end==' ')
330 {
331 2160 out += *(in++);
332 4842 continue;
333 }
334
335
6/8
✓ Branch 0 taken 39852 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 35316 times.
✓ Branch 3 taken 4536 times.
✓ Branch 4 taken 35316 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 35316 times.
✗ Branch 7 not taken.
39906 while (*end && *end!='>'&& *end!='<' && *(end+1)!=':') end++; //allow for conditionals and <:
336
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 4536 times.
4590 if (*end!='>')
337 {
338 54 out+=*(in++);
339 54 continue;
340 }
341
342 int depth = 0;
343
2/2
✓ Branch 0 taken 558 times.
✓ Branch 1 taken 4536 times.
5094 for (const char* depth_str = in+1; *depth_str=='^'; depth_str++)
344 {
345 558 depth++;
346 }
347
348
2/2
✓ Branch 0 taken 486 times.
✓ Branch 1 taken 4050 times.
4536 if (depth != in_macro_def)
349 {
350 486 string temp(in, end-in+1);
351 486 out+=temp;
352 486 in=end+1;
353
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 432 times.
486 if (depth > in_macro_def)
354 {
355
3/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
54 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 486 }
360
361
3/6
✓ Branch 0 taken 396 times.
✓ Branch 1 taken 3654 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 396 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
4050 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 4050 in += depth+1;
363
364 bool is_variadic_arg = false;
365
5/8
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 2160 times.
✓ Branch 2 taken 1890 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1890 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1890 times.
✗ Branch 7 not taken.
4050 if (in[0] == '.' && in[1] == '.' && in[2] == '.' && in[3] == '[')
366 {
367
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1872 times.
1890 if (end[-1] != ']')
368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 asar_throw_error(0, error_type_block, error_id_unclosed_vararg);
369
370 is_variadic_arg = true;
371 1872 in += 4;
372 1872 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 1872 times.
✓ Branch 1 taken 2160 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 1854 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
4032 if(is_variadic_arg && !current_macro->variadic) asar_throw_error(0, error_type_block, error_id_macro_not_varadic, "<...[math]>");
377 //*end=0;
378 2007 string param;
379 4014 string temp(in, end-in);
380
1/2
✓ Branch 0 taken 4014 times.
✗ Branch 1 not taken.
4014 resolvedefines(param, temp);
381 in = param.data();
382
1/2
✓ Branch 0 taken 4014 times.
✗ Branch 1 not taken.
4014 bool valid_named_param = confirmname(in);
383
2/2
✓ Branch 0 taken 2160 times.
✓ Branch 1 taken 1854 times.
4014 if (!is_variadic_arg)
384 {
385
3/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 2124 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
2160 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 2664 times.
✓ Branch 1 taken 108 times.
2772 for (int j=0;current_macro->arguments[j];j++)
388 {
389
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 648 times.
2664 if (!strcmp(in, current_macro->arguments[j]))
390 {
391 found=true;
392 2016 out+=current_macro_args[j];
393 break;
394 }
395 }
396 if (!found)
397 {
398
4/7
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 54 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 36 times.
216 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 927 snes_label ret;
404
8/10
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 1818 times.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 18 times.
✓ Branch 6 taken 18 times.
✓ Branch 7 taken 1836 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 18 times.
1890 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 1836 times.
✗ Branch 1 not taken.
1836 int arg_num = getnum(in);
406
407
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1836 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1836 if(forwardlabel) asar_throw_error(0, error_type_block, error_id_label_forward);
408
409
6/7
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1818 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
1836 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
6/9
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 1746 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 36 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 36 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 24 times.
1890 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 1746 out+=current_macro_args[arg_num+current_macro->numargs-1];
412 }
413 3762 in=end+1;
414
2/2
✓ Branch 0 taken 1746 times.
✓ Branch 1 taken 2016 times.
3762 if (is_variadic_arg) in++;
415 4266 }
416 233748 else out+=*(in++);
417 }
418 return out;
419 306 }
420