CMS 3D CMS Logo

cppFunctionSkipper.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from builtins import range
3 __author__="Aurelija"
4 __date__ ="$2010-09-23 15.00.20$"
5 
6 import re
7 
8 declarator = '(\*|&)?(\w|<|,|>|$|::)+'
9 cv_decl = '\s*(const|volatile|noexcept)\s*'
10 exception = 'throw\(((::)|\w|\s|,|<|>)*\)'
11 decl_param = '\s((\(%s\))|(%s))\s*\((\w|\s|\*|&|\.|=|\'|\"|-|<|>|,|(::))*\)'%(declarator, declarator)
12 operator = '(%s|)operator\s*(\(\)|\[\]|\s+(new|delete)(\s*\[\]|)|\->[*]{0,1}|[+\-*/%%^&|~!=<>,]{1,2}(=|))'%(declarator)
13 dm_init = '(:[^{]*)'
14 functStart_re = re.compile('(\s|~|^)((\(%s\))|(%s)|(%s))\s*\((%s|\w|\s|\*|&|\.|=|\'|\"|-|<|>|,|::)*\)(%s)?(%s)?\s*(%s)?\s*{'%(declarator, declarator, operator, decl_param, cv_decl, exception,dm_init), re.MULTILINE)
15 
16 def filterFiles(fileList):
17  files = []
18 
19  for i in range(len(fileList)):
20  if type(fileList[0]).__name__ != 'tuple':
21  file = fileList[i]
22  fileLines = filterFile(fileList[i])
23  else:
24  file = fileList[i][0]
25  fileLines = filterFile(fileList[i][1])
26 
27  files.append((file, fileLines))
28  return files
29 
30 def filterFile(file):
31 
32  lines = ""
33 
34  if type(file).__name__ != 'list':
35  lines = open(file).read()
36  else:
37  for line in file:
38  lines += line
39  fileLines = lines[:]
40  prevEndPosition = 0
41  endPosition = 0
42  while(True):
43  m = functStart_re.search(lines)
44  if m != None:
45  openBracket = 1
46  closeBracket = 0
47  startPosition = m.start()
48  #print "MATCH: " + lines[m.start():m.end()]
49  for i, character in enumerate(lines[m.end():]):
50  if character == "{":
51  openBracket += 1
52  elif character == "}":
53  closeBracket += 1
54  if openBracket == closeBracket :
55  prevEndPosition += endPosition
56  endPosition = m.end() + i + 1
57  break
58  if openBracket != closeBracket:#if there is error in file
59  print("Error in file. To much open brackets. Run commentSkipper before you run functionSkipper.")
60  break
61  else:
62  #print "LINES: \n" + lines[startPosition:endPosition]
63  #print "#############################################";
64  lines = delLines(lines, startPosition, endPosition)
65  fileLines = fileLines[:prevEndPosition] + lines
66  lines = lines[endPosition:]
67  else:
68  break
69 
70  listOfLines = []
71  startLine = 0
72  for index, character in enumerate(fileLines):
73  if character == "\n":
74  listOfLines.append(fileLines[startLine:index+1])
75  startLine = index + 1
76  listOfLines.append(fileLines[startLine:])
77  return listOfLines
78 
79 def delLines(string, startPosition, endPosition):
80  i = startPosition - 1
81  end = startPosition
82  while(True):
83  if i != -1 and string[i] != '\n':
84  i -= 1
85  else:
86  string = string[:i+1] + (end - i - 1)*' ' + string[end:]
87  break
88 
89  i = startPosition
90  start = startPosition
91  while(i != endPosition):
92  if string[i] != '\n':
93  i += 1
94  else:
95  string = string[:start] + (i-start)*str(" ") + string[i:]
96  i = i+1
97  start = i
98  string = string[:start] + (endPosition-start)*str(" ") + string[endPosition:]
99 
100  return string
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
cppFunctionSkipper.filterFile
def filterFile(file)
Definition: cppFunctionSkipper.py:30
cppFunctionSkipper.delLines
def delLines(string, startPosition, endPosition)
Definition: cppFunctionSkipper.py:79
str
#define str(s)
Definition: TestProcessor.cc:52
cppFunctionSkipper.filterFiles
def filterFiles(fileList)
Definition: cppFunctionSkipper.py:16
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
gpuVertexFinder::while
while(__syncthreads_or(more))
Definition: gpuClusterTracksIterative.h:109