MCPcopy Create free account
hub / github.com/compiler-explorer/compiler-explorer / removeUnusedLabels

Method removeUnusedLabels

lib/compilers/v.ts:166–196  ·  view source on GitHub ↗
(input: string[])

Source from the content-addressed store, hash-verified

164 }
165
166 removeUnusedLabels(input: string[]): string[] {
167 const output: string[] = [];
168
169 const lineRe = /^.*main__.*$/;
170 const mainFunctionCall = '\tmain__main();';
171
172 let scopeDepth = 0;
173 let insertNewLine = false;
174
175 for (const lineNo in input) {
176 const line = input[lineNo];
177 if (!line) continue;
178
179 if (insertNewLine) {
180 output.push('');
181 insertNewLine = false;
182 }
183
184 if ((scopeDepth === 0 && lineRe.test(line) && line !== mainFunctionCall) || scopeDepth > 0) {
185 const opening = (line.match(/{/g) || []).length - 1;
186 const closing = (line.match(/}/g) || []).length - 1;
187 scopeDepth += opening - closing;
188
189 output.push(line);
190
191 insertNewLine = scopeDepth === 0;
192 }
193 }
194
195 return output;
196 }
197
198 removeWhitespaceLines = (input: string[]) => input.map(line => line.trimStart()).filter(line => line !== '');
199 removeComments = (input: string[]) =>

Callers 1

processCLikeMethod · 0.95

Calls 3

pushMethod · 0.80
testMethod · 0.80
matchMethod · 0.80

Tested by

no test coverage detected