MC: Split convertFile() function into smaller pieces
Output of build/ stayed the same.
This commit is contained in:
parent
311630ac1c
commit
62b05193c4
|
@ -164,21 +164,7 @@ def parseStringComparison(line, pos1):
|
|||
|
||||
return None
|
||||
|
||||
def convertFile(srcname, destname):
|
||||
fin = open(srcname, "rt")
|
||||
srclines = fin.readlines()
|
||||
fin.close()
|
||||
|
||||
header = '#include "token.h"\n'
|
||||
header += '#include "errorlogger.h"\n'
|
||||
header += '#include <string>\n'
|
||||
header += '#include <cstring>\n'
|
||||
matchfunctions = ''
|
||||
code = ''
|
||||
|
||||
matchStrs = {}
|
||||
patternNumber = 1
|
||||
for line in srclines:
|
||||
def replaceTokenMatch(matchFunctions, matchStrs, line):
|
||||
while True:
|
||||
pos1 = line.find('Token::Match(')
|
||||
if pos1 == -1:
|
||||
|
@ -207,11 +193,13 @@ def convertFile(srcname, destname):
|
|||
a3 = ''
|
||||
if arg3:
|
||||
a3 = ',' + arg3
|
||||
patternNumber = len(matchFunctions) + 1
|
||||
line = line[:pos1]+'match'+str(patternNumber)+'('+arg1+a3+')'+line[pos1+len(g0):]
|
||||
matchfunctions += compilePattern(matchStrs, arg2, patternNumber, arg3)
|
||||
patternNumber += 1
|
||||
matchFunctions.append(compilePattern(matchStrs, arg2, patternNumber, arg3))
|
||||
|
||||
# Replace plain old C-string comparison with C++ strings
|
||||
return line
|
||||
|
||||
def replaceCStrings(matchStrs, line):
|
||||
while True:
|
||||
match = re.search('str\(\) (==|!=) "', line)
|
||||
if not match:
|
||||
|
@ -228,6 +216,28 @@ def convertFile(srcname, destname):
|
|||
text = line[startPos+1:endPos-1]
|
||||
line = line[:startPos] + insertMatchStr(matchStrs, text) + line[endPos:]
|
||||
|
||||
return line
|
||||
|
||||
def convertFile(srcname, destname):
|
||||
fin = open(srcname, "rt")
|
||||
srclines = fin.readlines()
|
||||
fin.close()
|
||||
|
||||
header = '#include "token.h"\n'
|
||||
header += '#include "errorlogger.h"\n'
|
||||
header += '#include <string>\n'
|
||||
header += '#include <cstring>\n'
|
||||
matchFunctions = []
|
||||
code = ''
|
||||
|
||||
matchStrs = {}
|
||||
for line in srclines:
|
||||
# Compile Token::Match and Token::simpleMatch
|
||||
line = replaceTokenMatch(matchFunctions, matchStrs, line)
|
||||
|
||||
# Cache plain C-strings in C++ strings
|
||||
line = replaceCStrings(matchStrs, line)
|
||||
|
||||
code += line
|
||||
|
||||
# Compute string list
|
||||
|
@ -235,8 +245,13 @@ def convertFile(srcname, destname):
|
|||
for match in sorted(matchStrs, key=matchStrs.get):
|
||||
stringList += 'static const std::string matchStr' + str(matchStrs[match]) + '("' + match + '");\n'
|
||||
|
||||
# Compute matchFunctions
|
||||
strFunctions = ''
|
||||
for function in matchFunctions:
|
||||
strFunctions += function;
|
||||
|
||||
fout = open(destname, 'wt')
|
||||
fout.write(header+stringList+matchfunctions+code)
|
||||
fout.write(header+stringList+strFunctions+code)
|
||||
fout.close()
|
||||
|
||||
# selftests..
|
||||
|
|
Loading…
Reference in New Issue