Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-19 01:15:13

0001 from __future__ import print_function
0002 from builtins import range
0003 __author__="Aurelija"
0004 __date__ ="$2010-09-23 15.00.20$"
0005 
0006 import re
0007 
0008 declarator = '(\*|&)?(\w|<|,|>|$|::)+'
0009 cv_decl = '\s*(const|volatile|noexcept)\s*'
0010 exception = 'throw\(((::)|\w|\s|,|<|>)*\)'
0011 decl_param = '\s((\(%s\))|(%s))\s*\((\w|\s|\*|&|\.|=|\'|\"|-|<|>|,|(::))*\)'%(declarator, declarator)
0012 operator = '(%s|)operator\s*(\(\)|\[\]|\s+(new|delete)(\s*\[\]|)|\-\>[*]{0,1}|[+\-*/%%^&|~!=<>,]{1,2}(=|))'%(declarator)
0013 dm_init = '(:[^{]*)'
0014 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)
0015 
0016 def filterFiles(fileList):
0017     files = []
0018 
0019     for i in range(len(fileList)):
0020         if type(fileList[0]).__name__ != 'tuple':
0021             file = fileList[i]
0022             fileLines = filterFile(fileList[i])
0023         else:
0024             file = fileList[i][0]
0025             fileLines = filterFile(fileList[i][1])
0026 
0027         files.append((file, fileLines))
0028     return files
0029 
0030 def filterFile(file):
0031 
0032     lines = ""
0033 
0034     if type(file).__name__ != 'list':
0035         lines = open(file, errors='replace').read()
0036     else:
0037         for line in file:
0038             lines += line
0039     fileLines = lines[:]
0040     prevEndPosition = 0
0041     endPosition = 0
0042     while(True):
0043         m = functStart_re.search(lines)
0044         if m != None:
0045             openBracket = 1
0046             closeBracket = 0
0047             startPosition = m.start()
0048             #print "MATCH: " + lines[m.start():m.end()]
0049             for i, character in enumerate(lines[m.end():]):
0050                 if character == "{":
0051                     openBracket += 1
0052                 elif character == "}":
0053                     closeBracket += 1
0054                     if openBracket == closeBracket :
0055                         prevEndPosition += endPosition
0056                         endPosition = m.end() + i + 1
0057                         break
0058             if openBracket != closeBracket:#if there is error in file
0059                 print("Error in file. To much open brackets. Run commentSkipper before you run functionSkipper.")
0060                 break
0061             else:
0062                 #print "LINES: \n" + lines[startPosition:endPosition] 
0063                 #print "#############################################";
0064                 lines = delLines(lines, startPosition, endPosition)
0065                 fileLines = fileLines[:prevEndPosition] + lines
0066                 lines = lines[endPosition:]
0067         else:
0068             break
0069 
0070     listOfLines = []
0071     startLine = 0
0072     for index, character in enumerate(fileLines):
0073         if character == "\n":
0074             listOfLines.append(fileLines[startLine:index+1])
0075             startLine = index + 1
0076     listOfLines.append(fileLines[startLine:])
0077     return listOfLines
0078 
0079 def delLines(string, startPosition, endPosition):
0080     i = startPosition - 1
0081     end = startPosition
0082     while(True):
0083         if i != -1 and string[i] != '\n':
0084             i -= 1
0085         else:
0086             string = string[:i+1] + (end - i - 1)*' ' + string[end:]
0087             break
0088 
0089     i = startPosition
0090     start = startPosition
0091     while(i != endPosition):
0092         if string[i] != '\n':
0093             i += 1
0094         else:
0095             string = string[:start] + (i-start)*str(" ") + string[i:]
0096             i = i+1
0097             start = i
0098     string = string[:start] + (endPosition-start)*str(" ") + string[endPosition:]
0099 
0100     return string