CMS 3D CMS Logo

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