python: The new module has been removed in python3
authorGiacomo Travaglini <giacomo.travaglini@arm.com>
Fri, 28 Feb 2020 13:42:03 +0000 (13:42 +0000)
committerGiacomo Travaglini <giacomo.travaglini@arm.com>
Tue, 10 Mar 2020 09:35:56 +0000 (09:35 +0000)
new.instance was used to instantiate a method bypassing the __init__
interface This patch is doing things properly by importing the LRTable
so that the LRParser interface is respected

Change-Id: I0b0ce184ef5ac297af40289a2896962c9a967a71
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/26243
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/python/m5/util/grammar.py

index caf8a2e39075c002cbb5bb7bf8e864957f2f93ba..e09c989eea6a853508e0be26c016ff5450509cd1 100644 (file)
@@ -98,17 +98,16 @@ class Grammar(object):
             raise AttributeError(
                 "argument must be a string, was '%s'" % type(f))
 
-        import new
         lexer = self.lex.clone()
         lexer.input(data)
         self.lexers.append((lexer, source))
-        dict = {
-            'productions' : self.yacc.productions,
-            'action'      : self.yacc.action,
-            'goto'        : self.yacc.goto,
-            'errorfunc'   : self.yacc.errorfunc,
-            }
-        parser = new.instance(ply.yacc.LRParser, dict)
+
+        lrtab = ply.yacc.LRTable()
+        lrtab.lr_productions = self.yacc.productions
+        lrtab.lr_action = self.yacc.action
+        lrtab.lr_goto = self.yacc.goto
+
+        parser = ply.yacc.LRParser(lrtab, self.yacc.errorfunc)
         result = parser.parse(lexer=lexer, debug=debug, tracking=tracking)
         self.lexers.pop()
         return result