From ee5464a92c88d604d26e8d2e52a176e6a706e9ea Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Fri, 12 Jan 2024 22:24:22 +0300 Subject: [PATCH] oppc: consider subscripts exprs --- src/openpower/oppc/pc_ast.py | 4 ++-- src/openpower/oppc/pc_parser.py | 12 ++++++------ src/openpower/oppc/pc_pseudocode.py | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/openpower/oppc/pc_ast.py b/src/openpower/oppc/pc_ast.py index de77765e..93df556a 100644 --- a/src/openpower/oppc/pc_ast.py +++ b/src/openpower/oppc/pc_ast.py @@ -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() diff --git a/src/openpower/oppc/pc_parser.py b/src/openpower/oppc/pc_parser.py index d88e67dd..cb60282b 100644 --- a/src/openpower/oppc/pc_parser.py +++ b/src/openpower/oppc/pc_parser.py @@ -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 diff --git a/src/openpower/oppc/pc_pseudocode.py b/src/openpower/oppc/pc_pseudocode.py index 0d111a81..a04a9924 100644 --- a/src/openpower/oppc/pc_pseudocode.py +++ b/src/openpower/oppc/pc_pseudocode.py @@ -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]), -- 2.30.2