Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: add type metadata to ast output #3644

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vyper/ast/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion vyper/compiler/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions vyper/semantics/types/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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"):
Expand Down
Loading