oppc: decouple call name class
authorDmitry Selyutin <ghostmansd@gmail.com>
Tue, 9 Jan 2024 15:49:56 +0000 (18:49 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 9 Jan 2024 15:49:56 +0000 (18:49 +0300)
src/openpower/oppc/pc_ast.py
src/openpower/oppc/pc_parser.py

index d139d2dbb9e10c0d971349a14ceba1178ee72a6c..9812107c869a4900ed1f7fc69173681bdc43f902 100644 (file)
@@ -67,10 +67,6 @@ class Sequence(Node, tuple, metaclass=SequenceMeta):
         return f"{hex(id(self))}@{self.__class__.__name__}({repr(list(self))})"
 
 
-class Arguments(Sequence):
-    pass
-
-
 class Scope(Sequence):
     pass
 
@@ -231,7 +227,13 @@ class RParenthesis(Token):
 
 
 class Call(Dataclass):
-    name: Symbol
+    class Name(Symbol):
+        pass
+
+    class Arguments(Sequence):
+        pass
+
+    name: Name
     args: Arguments
 
 
index 03adc6356b0d467fc3d6a776cf1a904b99e00d0c..33d2d8dbcd2655e8da4faa061e30aa206ae5992c 100644 (file)
@@ -425,13 +425,15 @@ class Parser:
                 node = p[2]
                 while isinstance(node.subject, attribute_or_subscript):
                     node = node.subject
-                if isinstance(node.subject, pc_ast.Arguments):
-                    node.subject = pc_ast.Call(name=p[1], args=node.subject)
+                if isinstance(node.subject, pc_ast.Call.Arguments):
+                    name = pc_ast.Call.Name(str(p[1]))
+                    node.subject = pc_ast.Call(name=name, args=node.subject)
                 else:
                     node.subject = p[1]
                 p[0] = p[2]
-            elif isinstance(p[2], pc_ast.Arguments):
-                p[0] = pc_ast.Call(name=p[1], args=p[2])
+            elif isinstance(p[2], pc_ast.Call.Arguments):
+                name = pc_ast.Call.Name(str(p[1]))
+                p[0] = pc_ast.Call(name=name, args=p[2])
             else:
                 raise NotImplementedError()
 
@@ -514,7 +516,7 @@ class Parser:
                         | LPAR RPAR
         """
         if len(p) == 3:
-            p[0] = pc_ast.Arguments()
+            p[0] = pc_ast.Call.Arguments()
         else:
             p[0] = p[2]
 
@@ -591,9 +593,9 @@ class Parser:
                 | argument
         """
         if len(p) == 4:
-            p[0] = pc_ast.Arguments(p[1] + (p[3],))
+            p[0] = pc_ast.Call.Arguments(p[1] + (p[3],))
         else:
-            p[0] = pc_ast.Arguments([p[1]])
+            p[0] = pc_ast.Call.Arguments([p[1]])
 
     # argument: test [gen_for] | test '=' test  # Really [keyword '='] test
     def p_argument(self, p):