test
CMS 3D CMS Logo

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