summaryrefslogtreecommitdiff
path: root/buildscripts/errorcodes.py
diff options
context:
space:
mode:
authorgregs <greg@10gen.com>2011-06-21 17:23:01 -0400
committergregs <greg@10gen.com>2011-06-21 17:23:01 -0400
commit7acd67609322bb2771228e84c7bc381d170f89b1 (patch)
tree89c04f941269c00749aecc3f448617c279b66cb8 /buildscripts/errorcodes.py
parent1d59eb6603fbd630ffc944563e48dd1ab5e8d091 (diff)
downloadmongo-7acd67609322bb2771228e84c7bc381d170f89b1.tar.gz
Auto-gen zero error codes.
Diffstat (limited to 'buildscripts/errorcodes.py')
-rwxr-xr-xbuildscripts/errorcodes.py56
1 files changed, 45 insertions, 11 deletions
diff --git a/buildscripts/errorcodes.py b/buildscripts/errorcodes.py
index 743ab698161..ce1b3e465d0 100755
--- a/buildscripts/errorcodes.py
+++ b/buildscripts/errorcodes.py
@@ -31,23 +31,57 @@ def assignErrorCodes():
codes = []
-def readErrorCodes( callback ):
- ps = [ re.compile( "([umsg]asser(t|ted)) *\( *(\d+)" ) ,
- re.compile( "(User|Msg|MsgAssertion)Exceptio(n)\( *(\d+)" ) ,
- re.compile( "((verify)) *\( *(\d+)" )
+def readErrorCodes( callback, replaceZero = False ):
+ ps = [ re.compile( "(([umsg]asser(t|ted))) *\( *(\d+)" ) ,
+ re.compile( "((User|Msg|MsgAssertion)Exceptio(n))\( *(\d+)" ) ,
+ re.compile( "(((verify))) *\( *(\d+)" )
]
+
for x in utils.getAllSourceFiles():
+
+ needReplace = [False]
+ lines = []
+ lastCodes = [0]
lineNum = 1
+
for line in open( x ):
+
for p in ps:
- for m in p.findall( line ):
- codes.append( ( x , lineNum , line , m[2] ) )
- callback( x , lineNum , line , m[2] )
- lineNum = lineNum + 1
+
+ def repl( m ):
+ m = m.groups()
+
+ start = m[0]
+ code = m[3]
+ if code == '0' and replaceZero :
+ code = getNextCode( lastCodes )
+ lastCodes.append( code )
+ code = str( code )
+ needReplace[0] = True
+
+ print( "Adding code " + code + " to line " + x + ":" + str( lineNum ) )
+
+ else :
+ codes.append( ( x , lineNum , line , code ) )
+ callback( x , lineNum , line , code )
+
+ return start + "( " + code
+
+ line = re.sub( p, repl, line )
+ if replaceZero : lines.append( line )
+ lineNum = lineNum + 1
+
+ if replaceZero and needReplace[0] :
+ print( "Replacing file " + x )
+ of = open( x + ".tmp", 'w' )
+ of.write( "".join( lines ) )
+ of.close()
+ os.rename( x + ".tmp", x )
+
-def getNextCode():
- highest = [0]
+def getNextCode( lastCodes = [0] ):
+ highest = [max(lastCodes)]
def check( fileName , lineNum , line , code ):
code = int( code )
if code > highest[0]:
@@ -65,7 +99,7 @@ def checkErrorCodes():
print( "%s:%d:%s %s" % seen[code] )
errors.append( seen[code] )
seen[code] = ( fileName , lineNum , line , code )
- readErrorCodes( checkDups )
+ readErrorCodes( checkDups, True )
return len( errors ) == 0
def getBestMessage( err , start ):