Skip to content

Commit

Permalink
wip: add type metadata to ast output
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Oct 12, 2023
1 parent 68da04b commit 9d778e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
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

0 comments on commit 9d778e0

Please sign in to comment.