MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / removeblocks

Method removeblocks

tools/reduce.py:205–243  ·  view source on GitHub ↗
(self, filedata)

Source from the content-addressed store, hash-verified

203 self.replaceandrun('remove preprocessor directive', filedata, i, '')
204
205 def removeblocks(self, filedata):
206 if len(filedata) < 3:
207 return filedata
208
209 for i in range(len(filedata)):
210 strippedline = filedata[i].strip()
211 if len(strippedline) == 0:
212 continue
213 if strippedline[-1] not in ';{}':
214 continue
215
216 i1 = i + 1
217 while i1 < len(filedata) and filedata[i1].startswith('#'):
218 i1 = i1 + 1
219
220 i2 = i1
221 indent = 0
222 while i2 < len(filedata):
223 for c in filedata[i2]:
224 if c == '}':
225 indent = indent - 1
226 if indent == 0:
227 indent = -100
228 elif c == '{':
229 indent = indent + 1
230 if indent < 0:
231 break
232 i2 = i2 + 1
233 if indent == -100:
234 indent = 0
235 if i2 == i1 or i2 >= len(filedata):
236 continue
237 if filedata[i2].strip() != '}' and filedata[i2].strip() != '};':
238 continue
239 if indent < 0:
240 i2 = i2 - 1
241 filedata = self.clearandrun('remove codeblock', filedata, i1, i2)
242
243 return filedata
244
245 def removeline(self, filedata):
246 stmt = True

Callers 1

mainFunction · 0.95

Calls 1

clearandrunMethod · 0.95

Tested by

no test coverage detected