From 9d778e0b46d41fa456459fa4598775a49e661291 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 12 Oct 2023 11:51:18 -0400 Subject: [PATCH] wip: add type metadata to ast output --- vyper/ast/nodes.py | 2 +- vyper/compiler/output.py | 2 +- vyper/semantics/types/base.py | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/vyper/ast/nodes.py b/vyper/ast/nodes.py index 2497928035..66ccc19310 100644 --- a/vyper/ast/nodes.py +++ b/vyper/ast/nodes.py @@ -409,7 +409,7 @@ def to_dict(self) -> dict: ast_dict[key] = _to_dict(value) if "type" in self._metadata: - ast_dict["type"] = str(self._metadata["type"]) + ast_dict["type"] = self._metadata["type"].to_json() return ast_dict diff --git a/vyper/compiler/output.py b/vyper/compiler/output.py index 1c38fcff9b..7ae27a5697 100644 --- a/vyper/compiler/output.py +++ b/vyper/compiler/output.py @@ -18,7 +18,7 @@ def build_ast_dict(compiler_data: CompilerData) -> dict: ast_dict = { "contract_name": compiler_data.contract_name, - "ast": ast_to_dict(compiler_data.vyper_module), + "ast": ast_to_dict(compiler_data.vyper_module_folded), } return ast_dict diff --git a/vyper/semantics/types/base.py b/vyper/semantics/types/base.py index c5af5c2a39..d24987d70f 100644 --- a/vyper/semantics/types/base.py +++ b/vyper/semantics/types/base.py @@ -300,6 +300,9 @@ def get_member(self, key: str, node: vy_ast.VyperNode) -> "VyperType": def __repr__(self): return self._id + def to_json(self): + return repr(self) # very simple implementation + class KwargSettings: # convenience class which holds metadata about how to process kwargs. @@ -313,6 +316,9 @@ def __init__(self, typ, default, require_literal=False): self.default = default self.require_literal = require_literal + def to_json(self): + return repr(self) # very simple implementation + # A type type. Used internally for types which can live in expression # position, ex. constructors (events, interfaces and structs), and also @@ -324,6 +330,9 @@ def __init__(self, typedef): def __repr__(self): return f"type({self.typedef})" + def to_json(self): + return {"type_t": self.typedef.to_json()} + # dispatch into ctor if it's called def fetch_call_return(self, node): if hasattr(self.typedef, "_ctor_call_return"):