oppc: consider subscripts exprs
authorDmitry Selyutin <ghostmansd@gmail.com>
Fri, 12 Jan 2024 19:24:22 +0000 (22:24 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Fri, 12 Jan 2024 19:29:16 +0000 (22:29 +0300)
src/openpower/oppc/pc_ast.py
src/openpower/oppc/pc_parser.py
src/openpower/oppc/pc_pseudocode.py

index de77765e2fea8edb3a8318a82073afea2a2a0409..93df556a8d6107438a0b5d2d4e94777d9af5b7bb 100644 (file)
@@ -538,12 +538,12 @@ class RepeatExpr(Dataclass):
     times: Node
 
 
-class Subscript(Dataclass):
+class SubscriptExpr(Dataclass):
     index: Node
     subject: Node = Node()
 
 
-class RangeSubscript(Dataclass):
+class RangeSubscriptExpr(Dataclass):
     start: Node
     end: Node = Node()
     subject: Node = Node()
index d88e67dd7eb06fe254eea5d15c090715fa0ab3d5..cb60282b22c5eb3ff5ea4cd206888464290be74c 100644 (file)
@@ -418,8 +418,8 @@ class Parser:
         else:
             attribute_or_subscript = (
                 pc_ast.Attribute,
-                pc_ast.Subscript,
-                pc_ast.RangeSubscript,
+                pc_ast.SubscriptExpr,
+                pc_ast.RangeSubscriptExpr,
             )
             if isinstance(p[2], attribute_or_subscript):
                 node = p[2]
@@ -505,8 +505,8 @@ class Parser:
         else:
             attribute_or_subscript = (
                 pc_ast.Attribute,
-                pc_ast.Subscript,
-                pc_ast.RangeSubscript,
+                pc_ast.SubscriptExpr,
+                pc_ast.RangeSubscriptExpr,
             )
             if isinstance(p[2], attribute_or_subscript):
                 node = p[2]
@@ -554,9 +554,9 @@ class Parser:
                      | test
         """
         if len(p) == 4:
-            p[0] = pc_ast.RangeSubscript(start=p[1], end=p[3])
+            p[0] = pc_ast.RangeSubscriptExpr(start=p[1], end=p[3])
         else:
-            p[0] = pc_ast.Subscript(index=p[1])
+            p[0] = pc_ast.SubscriptExpr(index=p[1])
 
     # testlist: test (',' test)* [',']
     # Contains shift/reduce error
index 0d111a81fb8d6d9c744770bc0d32f8e709421b35..a04a99249907a87d40374470241e3dbce54788d4 100644 (file)
@@ -51,7 +51,7 @@ class PseudocodeVisitor(pc_util.Visitor):
         yield node
         lvalue = str(self[node.lvalue])
         if (isinstance(node.lvalue, (pc_ast.GPR, pc_ast.FPR)) or
-                (isinstance(node.lvalue, (pc_ast.Subscript, pc_ast.RangeSubscript)) and
+                (isinstance(node.lvalue, (pc_ast.SubscriptExpr, pc_ast.RangeSubscriptExpr)) and
                     isinstance(node.lvalue.subject, (pc_ast.GPR, pc_ast.FPR)))):
             lvalue = lvalue.replace("(", "").replace(")", "")
         rvalue = str(self[node.rvalue])
@@ -274,8 +274,8 @@ class PseudocodeVisitor(pc_util.Visitor):
         stmt = mapping[node.__class__]
         self[node].emit(stmt=stmt)
 
-    @pc_util.Hook(pc_ast.Subscript)
-    def Subscript(self, node):
+    @pc_util.Hook(pc_ast.SubscriptExpr)
+    def SubscriptExpr(self, node):
         yield node
         stmt = "".join([
             str(self[node.subject]),
@@ -285,8 +285,8 @@ class PseudocodeVisitor(pc_util.Visitor):
         ])
         self[node].emit(stmt=stmt)
 
-    @pc_util.Hook(pc_ast.RangeSubscript)
-    def RangeSubscript(self, node):
+    @pc_util.Hook(pc_ast.RangeSubscriptExpr)
+    def RangeSubscriptExpr(self, node):
         yield node
         stmt = "".join([
             str(self[node.subject]),