]> granicus.if.org Git - clang/commitdiff
Portable Python script across Python version
authorSerge Guelton <sguelton@quarkslab.com>
Tue, 18 Dec 2018 08:24:06 +0000 (08:24 +0000)
committerSerge Guelton <sguelton@quarkslab.com>
Tue, 18 Dec 2018 08:24:06 +0000 (08:24 +0000)
Replace `xrange(...)` by either `range(...)` or `list(range(...))` depending on the context.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349448 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/python/clang/cindex.py
utils/ABITest/Enumeration.py
utils/ABITest/TypeGen.py
utils/modfuzz.py

index 939213d302d61e1c2f67b8f57227313521bf875e..72e8fdb8a8b6f19c2c9a04299edb53c5c5e0471f 100644 (file)
@@ -109,8 +109,6 @@ if sys.version_info[0] == 3:
             return x
         return x.encode('utf8')
 
-    xrange = range
-
 elif sys.version_info[0] == 2:
     # Python 2 strings are utf8 byte strings, no translation is needed for
     # C-interop.
@@ -556,7 +554,7 @@ class TokenGroup(object):
 
         token_group = TokenGroup(tu, tokens_memory, tokens_count)
 
-        for i in xrange(0, count):
+        for i in range(0, count):
             token = Token()
             token.int_data = tokens_array[i].int_data
             token.ptr_data = tokens_array[i].ptr_data
@@ -3190,7 +3188,7 @@ class CompileCommand(object):
         Invariant : the first argument is the compiler executable
         """
         length = conf.lib.clang_CompileCommand_getNumArgs(self.cmd)
-        for i in xrange(length):
+        for i in range(length):
             yield conf.lib.clang_CompileCommand_getArg(self.cmd, i)
 
 class CompileCommands(object):
index 01830a38cdf229550da0ced879816aa44ce700ce..29a81b4f13f1dc55d4e96193b18f15b279cf6fed 100644 (file)
@@ -199,7 +199,7 @@ def getNthPairVariableBounds(N, bounds):
         raise ValueError("Invalid input (out of bounds)")
 
     level = 0
-    active = range(len(bounds))
+    active = list(range(len(bounds)))
     active.sort(key=lambda i: bounds[i])
     prevLevel = 0
     for i,index in enumerate(active):
index 8330340cd3df9936232428939ec41b6b153c85c0..f8a4d07e11d6105df6e9dd58b8e91fd32a601124 100644 (file)
@@ -242,7 +242,7 @@ def combinations(values, k):
     # combinations, selections of a sequence
     if k==0: yield []
     else:
-        for i in xrange(len(values)-k+1):
+        for i in range(len(values)-k+1):
             for cc in combinations(values[i+1:],k-1):
                 yield [values[i]]+cc
 
index 885621d14e425d3c1f5799420ef7474f2efa7f6f..948603338cc74b110698b05faaf631d9d347a43b 100644 (file)
@@ -106,7 +106,7 @@ def generate():
   try:
     while True:
       assert m, 'got a failure with no steps; broken clang binary?'
-      i = random.choice(range(len(m)))
+      i = random.choice(list(range(len(m))))
       x = m[0:i] + m[i+1:]
       m2 = CodeModel()
       for d in x: