From 9605c11c4c3127e3b1749eb4f65b80e9e7db0d8e Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Tue, 8 Feb 2000 18:57:32 +0000 Subject: [PATCH] move constants out of transformer so that they can be shared with ast add varargs and kwargs attributes to Function nodes --- Lib/compiler/ast.py | 7 +++++++ Lib/compiler/transformer.py | 10 ++-------- Tools/compiler/compiler/ast.py | 7 +++++++ Tools/compiler/compiler/transformer.py | 10 ++-------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Lib/compiler/ast.py b/Lib/compiler/ast.py index 9c214d453d..1715a7f65c 100644 --- a/Lib/compiler/ast.py +++ b/Lib/compiler/ast.py @@ -1,4 +1,5 @@ import types +from consts import CO_VARARGS, CO_VARKEYWORDS nodes = {} @@ -85,6 +86,12 @@ class Function(Node): self.code = code self._children = ('function', name, argnames, defaults, flags, doc, code) + self.varargs = self.kwargs = None + if flags & CO_VARARGS: + self.varargs = 1 + if flags & CO_VARKEYWORDS: + self.kwargs = 1 + def __repr__(self): return "Function(%s,%s,%s,%s,%s,%s)" % self._children[1:] diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py index 9200f7acbd..42d34dcbdc 100644 --- a/Lib/compiler/transformer.py +++ b/Lib/compiler/transformer.py @@ -99,14 +99,8 @@ import pprint error = 'walker.error' -# code flags -CO_VARARGS = 1 -CO_VARKEYWORDS = 2 - -# operation flags -OP_ASSIGN = 'OP_ASSIGN' -OP_DELETE = 'OP_DELETE' -OP_APPLY = 'OP_APPLY' +from consts import CO_VARARGS, CO_VARKEYWORDS +from consts import OP_ASSIGN, OP_DELETE, OP_APPLY def asList(nodes): l = [] diff --git a/Tools/compiler/compiler/ast.py b/Tools/compiler/compiler/ast.py index 9c214d453d..1715a7f65c 100644 --- a/Tools/compiler/compiler/ast.py +++ b/Tools/compiler/compiler/ast.py @@ -1,4 +1,5 @@ import types +from consts import CO_VARARGS, CO_VARKEYWORDS nodes = {} @@ -85,6 +86,12 @@ class Function(Node): self.code = code self._children = ('function', name, argnames, defaults, flags, doc, code) + self.varargs = self.kwargs = None + if flags & CO_VARARGS: + self.varargs = 1 + if flags & CO_VARKEYWORDS: + self.kwargs = 1 + def __repr__(self): return "Function(%s,%s,%s,%s,%s,%s)" % self._children[1:] diff --git a/Tools/compiler/compiler/transformer.py b/Tools/compiler/compiler/transformer.py index 9200f7acbd..42d34dcbdc 100644 --- a/Tools/compiler/compiler/transformer.py +++ b/Tools/compiler/compiler/transformer.py @@ -99,14 +99,8 @@ import pprint error = 'walker.error' -# code flags -CO_VARARGS = 1 -CO_VARKEYWORDS = 2 - -# operation flags -OP_ASSIGN = 'OP_ASSIGN' -OP_DELETE = 'OP_DELETE' -OP_APPLY = 'OP_APPLY' +from consts import CO_VARARGS, CO_VARKEYWORDS +from consts import OP_ASSIGN, OP_DELETE, OP_APPLY def asList(nodes): l = [] -- 2.40.0