Portable Python script across Python version

Python2 supports the two following equivalent construct

	raise ExceptionType, exception_value
and
	raise ExceptionType(exception_value)

Only the later is supported by Python3.

Differential Revision: https://reviews.llvm.org/D55195

llvm-svn: 348126
diff --git a/clang/utils/ABITest/ABITestGen.py b/clang/utils/ABITest/ABITestGen.py
index 27cc5ec..d45ac77d 100755
--- a/clang/utils/ABITest/ABITestGen.py
+++ b/clang/utils/ABITest/ABITestGen.py
@@ -250,7 +250,7 @@
                     elements[i] = v
                     yield '{ %s }'%(', '.join(elements))
         else:
-            raise NotImplementedError,'Cannot make tests values of type: "%s"'%(t,)
+            raise NotImplementedError('Cannot make tests values of type: "%s"'%(t,))
 
     def printSizeOfType(self, prefix, name, t, output=None, indent=2):
         print >>output, '%*sprintf("%s: sizeof(%s) = %%ld\\n", (long)sizeof(%s));'%(indent, '', prefix, name, name) 
@@ -310,7 +310,7 @@
                 else:
                     self.printValueOfType(prefix, '%s[%d]'%(name,i), t.elementType, output=output,indent=indent)                    
         else:
-            raise NotImplementedError,'Cannot print value of type: "%s"'%(t,)
+            raise NotImplementedError('Cannot print value of type: "%s"'%(t,))
 
     def checkTypeValues(self, nameLHS, nameRHS, t, output=None, indent=2):
         prefix = 'foo'
@@ -343,7 +343,7 @@
                     self.checkTypeValues('%s[%d]'%(nameLHS,i), '%s[%d]'%(nameRHS,i), 
                                          t.elementType, output=output,indent=indent)                    
         else:
-            raise NotImplementedError,'Cannot print value of type: "%s"'%(t,)
+            raise NotImplementedError('Cannot print value of type: "%s"'%(t,))
 
 import sys
 
@@ -642,7 +642,7 @@
     def write(N):
         try:
             FT = ftg.get(N)
-        except RuntimeError,e:
+        except RuntimeError as e:
             if e.args[0]=='maximum recursion depth exceeded':
                 print >>sys.stderr,'WARNING: Skipped %d, recursion limit exceeded (bad arguments?)'%(N,)
                 return
diff --git a/clang/utils/ABITest/Enumeration.py b/clang/utils/ABITest/Enumeration.py
index 47e4702..eb53e17 100644
--- a/clang/utils/ABITest/Enumeration.py
+++ b/clang/utils/ABITest/Enumeration.py
@@ -17,7 +17,7 @@
         return 1
 
     def __sub__(self, b):
-        raise ValueError,"Cannot subtract aleph0"
+        raise ValueError("Cannot subtract aleph0")
     __rsub__ = __sub__
 
     def __add__(self, b): 
@@ -86,9 +86,9 @@
     Return the N-th pair such that 0 <= x < W and 0 <= y < H."""
 
     if W <= 0 or H <= 0:
-        raise ValueError,"Invalid bounds"
+        raise ValueError("Invalid bounds")
     elif N >= W*H:
-        raise ValueError,"Invalid input (out of bounds)"
+        raise ValueError("Invalid input (out of bounds)")
 
     # Simple case...
     if W is aleph0 and H is aleph0:
@@ -170,7 +170,7 @@
     N -= 1
     if maxElement is not aleph0:
         if maxSize is aleph0:
-            raise NotImplementedError,'Max element size without max size unhandled'
+            raise NotImplementedError('Max element size without max size unhandled')
         bounds = [maxElement**i for i in range(1, maxSize+1)]
         S,M = getNthPairVariableBounds(N, bounds)
     else:
@@ -193,9 +193,9 @@
     bounds[x]."""
 
     if not bounds:
-        raise ValueError,"Invalid bounds"
+        raise ValueError("Invalid bounds")
     if not (0 <= N < sum(bounds)):
-        raise ValueError,"Invalid input (out of bounds)"
+        raise ValueError("Invalid input (out of bounds)")
 
     level = 0
     active = range(len(bounds))
@@ -216,7 +216,7 @@
             N -= levelSize
             prevLevel = level
     else:
-        raise RuntimError,"Unexpected loop completion"
+        raise RuntimError("Unexpected loop completion")
 
 def getNthPairVariableBoundsChecked(N, bounds, GNVP=getNthPairVariableBounds):
     x,y = GNVP(N,bounds)
diff --git a/clang/utils/ABITest/TypeGen.py b/clang/utils/ABITest/TypeGen.py
index 1e4471c..7bbf0d8 100644
--- a/clang/utils/ABITest/TypeGen.py
+++ b/clang/utils/ABITest/TypeGen.py
@@ -435,7 +435,7 @@
             if (self._cardinality is aleph0) or prev==self._cardinality:
                 break
         else:
-            raise RuntimeError,"Infinite loop in setting cardinality"
+            raise RuntimeError("Infinite loop in setting cardinality")
 
     def generateType(self, N):
         index,M = getNthPairVariableBounds(N, self.bounds)
@@ -466,7 +466,7 @@
         if i == atg.cardinality:
             try:
                 atg.get(i)
-                raise RuntimeError,"Cardinality was wrong"
+                raise RuntimeError("Cardinality was wrong")
             except AssertionError:
                 break
         print '%4d: %s'%(i, atg.get(i))
diff --git a/clang/utils/analyzer/SATestBuild.py b/clang/utils/analyzer/SATestBuild.py
index fbf3882..95dd69d 100755
--- a/clang/utils/analyzer/SATestBuild.py
+++ b/clang/utils/analyzer/SATestBuild.py
@@ -382,7 +382,7 @@
             check_call(Command, cwd=Dir, stderr=LogFile,
                        stdout=LogFile,
                        shell=True)
-        except CalledProcessError, e:
+        except CalledProcessError as e:
             Local.stderr.write("Error: Analyzes of %s failed. "
                                "See %s for details."
                                "Error code %d.\n" % (
diff --git a/clang/utils/token-delta.py b/clang/utils/token-delta.py
index 327fa92..f912547 100755
--- a/clang/utils/token-delta.py
+++ b/clang/utils/token-delta.py
@@ -37,7 +37,7 @@
         # O(N^2) case unless user requests it.
         if not force:
             if not self.getTestResult(changes):
-                raise ValueError,'Initial test passed to delta fails.'
+                raise ValueError('Initial test passed to delta fails.')
 
         # Check empty set first to quickly find poor test functions.
         if self.getTestResult(set()):