asar coverage - build #


src/asar/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
37 of 37, 0 excluded
100.0%
Functions:
6 of 6, 0 excluded
100.0%
Branches:
14 of 22, 0 excluded
63.6%

asar.h
Line Branch Exec Source
1 #if (defined(__sun__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)) && !defined(linux)
2 #error Please use -Dlinux on non-Linux Unix-likes.
3 #endif
4
5 #if defined(linux) && !defined(stricmp)
6 #error Please use -Dstricmp=strcasecmp on Unix-like systems.
7 #endif
8
9 #pragma once
10 #define Asar
11
12 #include "assocarr.h"
13 #include "libstr.h"
14 #include "libsmw.h"
15 #include "errors.h"
16 #include "warnings.h"
17 #include "virtualfile.h"
18 #include "assembleblock.h" // for snes_label - TODO do we want this here???
19 #include <cstdint>
20 #include <vector>
21
22 extern unsigned const char * romdata_r;
23 extern int romlen_r;
24
25 10697 inline void verify_paren(autoptr<char **> &ptr)
26 {
27
2/4
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 5309 times.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 5388 times.
10697 if(!ptr) throw_err_block(0, err_mismatched_parentheses);
28 10697 }
29
30 bool is_hex_constant(const char * str);
31 int getlenforlabel(snes_label thislabel, bool exists);
32 int getlenforlabel(int labelpos, int labelfreespace, bool exists);
33
34 bool validatedefinename(const char * name);
35
36 string create_symbols_file(string format, uint32_t romCrc);
37
38 void parse_std_includes(const char* textfile, autoarray<string>& outarray);
39 void parse_std_defines(const char* textfile);
40
41 void reseteverything();
42
43 void resolvedefines(string& out, const char * start);
44
45 int get_version_int();
46
47 bool setmapper();
48
49 void assemblefile(const char * filename);
50 void assembleline(const char * fname, int linenum, const string& line, int& single_line_for_tracker);
51
52 bool do_line_logic(const string& line, const char* filename, int lineno);
53
54 bool file_included_once(const char* file);
55
56 void get_current_line_details(string* location, string* details, bool exclude_block=false);
57 string get_callstack();
58
59 void throw_vfile_error(int whichpass, virtual_file_error vfile_error, const char* filename);
60
61 virtual_file_error asar_get_last_io_error();
62
63 extern int recursioncount;
64 extern int pass;
65
66 void init_stack_use_check();
67 void deinit_stack_use_check();
68 bool have_enough_stack_left();
69
70 class recurseblock {
71 public:
72 114025 recurseblock()
73 {
74 114025 recursioncount++;
75 #if !defined(_WIN32) && defined(NO_USE_THREADS)
76 if(recursioncount > 500)
77 #else
78
10/12
recurseblock::recurseblock():
✓ Branch 3 → 4 taken 56724 times.
✗ Branch 3 → 5 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 56723 times.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 11 taken 56723 times.
recurseblock::recurseblock():
✓ Branch 3 → 4 taken 57301 times.
✗ Branch 3 → 5 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 57300 times.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 11 taken 57300 times.
114025 if(!have_enough_stack_left() || recursioncount > 5000)
79 #endif
80 2 throw_err_fatal(pass, err_recursion_limit);
81 114023 }
82 114023 ~recurseblock()
83 {
84 114023 recursioncount--;
85 114023 }
86 };
87
88 extern const int asarver_maj;
89 extern const int asarver_min;
90 extern const int asarver_bug;
91 extern const bool asarver_beta;
92
93 extern bool asarverallowed;
94
95 extern bool moreonline;
96
97 extern bool checksum_fix_enabled;
98 extern bool force_checksum_fix;
99
100 extern int incsrcdepth;
101
102 extern bool ignoretitleerrors;
103
104 extern int optimizeforbank;
105
106 extern int in_macro_def;
107
108 extern int cur_logical_lineno;
109
110 //this is a trick to namespace an enum to avoid name collision without too much verbosity
111 //could technically name the enum too but this is fine for now.
112 namespace optimize_dp_flag {
113 enum : int {
114 NONE, //don't optimize
115 RAM, //bank 7E only (always uses dp base)
116 ALWAYS //bank 00-3F[|80] and 7E (always uses dp base)
117 };
118 }
119
120 extern int optimize_dp;
121 extern int dp_base;
122
123 namespace optimize_address_flag {
124 enum : int {
125 DEFAULT,//simply use optimizeforbank
126 RAM, //default+bank 7E only RAM address < $2000
127 MIRRORS //ram+if optimizeforbank is 00-3F[|80] and address < $8000
128 };
129 }
130
131 extern int optimize_address;
132
133 extern bool errored;
134
135 extern assocarr<string> clidefines;
136
137 extern virtual_filesystem* filesystem;
138
139 extern assocarr<string> defines;
140
141 extern assocarr<string> builtindefines;
142
143
144 enum class callstack_entry_type : int {
145 FILE,
146 MACRO_CALL,
147 LINE,
148 BLOCK,
149 };
150
151 struct callstack_entry {
152 callstack_entry_type type;
153 const char* content;
154 int lineno;
155
156 143033 callstack_entry(callstack_entry_type type, const char* content, int lineno)
157 143033 : type(type), content(content), lineno(lineno)
158 143033 {}
159 };
160
161
162 struct printable_callstack_entry {
163 string fullpath;
164 string prettypath;
165 int lineno;
166 string details;
167 };
168
169
170 extern std::vector<callstack_entry> callstack;
171 extern bool simple_callstacks;
172
173 class callstack_push {
174 public:
175 // the `content` here MUST outlive the callstack_push object, and must not be mutated after passing it to callstack_push.
176 143033 callstack_push(callstack_entry_type type, const char* content, int lineno=-1)
177 {
178
2/6
callstack_push::callstack_push(callstack_entry_type, char const*, int):
✓ Branch 3 → 4 taken 71058 times.
✗ Branch 3 → 5 not taken.
callstack_push::callstack_push(callstack_entry_type, char const*, int):
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✓ Branch 6 → 7 taken 71975 times.
✗ Branch 6 → 9 not taken.
143033 callstack.emplace_back(callstack_entry(type, content, lineno));
179 143033 }
180
181 143033 ~callstack_push()
182 {
183 143033 callstack.pop_back();
184 143033 }
185 };
186
187 bool in_top_level_file();
188 const char* get_current_file_name();
189 int get_current_line();
190 const char* get_current_block();
191
192 void get_full_printable_callstack(autoarray<printable_callstack_entry>* out, int indentation, bool add_lines);
193
194 #if !defined(NO_USE_THREADS) && !defined(RUN_VIA_THREAD)
195 // RPG Hacker: This is currently disabled for debug builds, because it causes random crashes
196 // when used in combination with -fsanitize=address.
197 # if defined(_WIN32) && defined(NDEBUG)
198 # define RUN_VIA_FIBER
199 # else
200 # define RUN_VIA_THREAD
201 # endif
202 #endif
203