Skip to content

Commit

Permalink
change unannotated_ast/ast to ast/annotated_ast, respectively
Browse files Browse the repository at this point in the history
also rename CompilerData.vyper_module_annotated to
CompilerData.annotated_vyper_module.
  • Loading branch information
charles-cooper committed Dec 31, 2023
1 parent 58f25b6 commit 580bd89
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
10 changes: 5 additions & 5 deletions vyper/ast/natspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
USERDOCS_FIELDS = ("notice",)


def parse_natspec(vyper_module_annotated: vy_ast.Module) -> Tuple[dict, dict]:
def parse_natspec(annotated_vyper_module: vy_ast.Module) -> Tuple[dict, dict]:
"""
Parses NatSpec documentation from a contract.
Arguments
---------
vyper_module_annotated : Module
annotated_vyper_module: Module
Module-level vyper ast node.
interface_codes: Dict, optional
Dict containing relevant data for any import statements related to
Expand All @@ -33,15 +33,15 @@ def parse_natspec(vyper_module_annotated: vy_ast.Module) -> Tuple[dict, dict]:
from vyper.semantics.types.function import FunctionVisibility

userdoc, devdoc = {}, {}
source: str = vyper_module_annotated.full_source_code
source: str = annotated_vyper_module.full_source_code

docstring = vyper_module_annotated.get("doc_string.value")
docstring = annotated_vyper_module.get("doc_string.value")
if docstring:
devdoc.update(_parse_docstring(source, docstring, ("param", "return")))
if "notice" in devdoc:
userdoc["notice"] = devdoc.pop("notice")

for node in [i for i in vyper_module_annotated.body if i.get("doc_string.value")]:
for node in [i for i in annotated_vyper_module.body if i.get("doc_string.value")]:
docstring = node.doc_string.value
func_type = node._metadata["func_type"]
if func_type.visibility != FunctionVisibility.EXTERNAL:
Expand Down
6 changes: 3 additions & 3 deletions vyper/cli/vyper_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
devdoc - Natspec developer documentation
combined_json - All of the above format options combined as single JSON output
layout - Storage layout of a Vyper contract
ast - Annotated AST in JSON format
unannotated_ast - Unannotated AST in JSON format
ast - AST (not yet annotated) in JSON format
annotated_ast - Annotated AST in JSON format
interface - Vyper interface of a contract
external_interface - External interface of a contract, used for outside contract calls
opcodes - List of opcodes as a string
Expand Down Expand Up @@ -260,7 +260,7 @@ def compile_files(
"abi_python": "abi",
"json": "abi",
"ast": "ast_dict",
"unannotated_ast": "unannotated_ast_dict",
"annotated_ast": "annotated_ast_dict",
"ir_json": "ir_dict",
}
final_formats = [translate_map.get(i, i) for i in output_formats]
Expand Down
5 changes: 3 additions & 2 deletions vyper/compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

OUTPUT_FORMATS = {
# requires vyper_module
"unannotated_ast_dict": output.build_ast_dict,
"ast_dict": output.build_annotated_ast_dict,
"ast_dict": output.build_ast_dict,
# requires annotated_vyper_module
"annotated_ast_dict": output.build_annotated_ast_dict,
"layout": output.build_layout_output,
# requires global_ctx
"devdoc": output.build_devdoc,
Expand Down
14 changes: 7 additions & 7 deletions vyper/compiler/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ def build_ast_dict(compiler_data: CompilerData) -> dict:
def build_annotated_ast_dict(compiler_data: CompilerData) -> dict:
annotated_ast_dict = {
"contract_name": str(compiler_data.contract_path),
"ast": ast_to_dict(compiler_data.vyper_module_annotated),
"ast": ast_to_dict(compiler_data.annotated_vyper_module),
}
return annotated_ast_dict


def build_devdoc(compiler_data: CompilerData) -> dict:
userdoc, devdoc = parse_natspec(compiler_data.vyper_module_annotated)
userdoc, devdoc = parse_natspec(compiler_data.annotated_vyper_module)
return devdoc


def build_userdoc(compiler_data: CompilerData) -> dict:
userdoc, devdoc = parse_natspec(compiler_data.vyper_module_annotated)
userdoc, devdoc = parse_natspec(compiler_data.annotated_vyper_module)
return userdoc


def build_external_interface_output(compiler_data: CompilerData) -> str:
interface = compiler_data.vyper_module_annotated._metadata["type"].interface
interface = compiler_data.annotated_vyper_module._metadata["type"].interface
stem = PurePath(compiler_data.contract_path).stem
# capitalize words separated by '_'
# ex: test_interface.vy -> TestInterface
Expand All @@ -61,7 +61,7 @@ def build_external_interface_output(compiler_data: CompilerData) -> str:


def build_interface_output(compiler_data: CompilerData) -> str:
interface = compiler_data.vyper_module_annotated._metadata["type"].interface
interface = compiler_data.annotated_vyper_module._metadata["type"].interface
out = ""

if interface.events:
Expand Down Expand Up @@ -166,7 +166,7 @@ def _to_dict(func_t):


def build_method_identifiers_output(compiler_data: CompilerData) -> dict:
module_t = compiler_data.vyper_module_annotated._metadata["type"]
module_t = compiler_data.annotated_vyper_module._metadata["type"]
functions = module_t.function_defs

return {
Expand All @@ -175,7 +175,7 @@ def build_method_identifiers_output(compiler_data: CompilerData) -> dict:


def build_abi_output(compiler_data: CompilerData) -> list:
module_t = compiler_data.vyper_module_annotated._metadata["type"]
module_t = compiler_data.annotated_vyper_module._metadata["type"]
_ = compiler_data.ir_runtime # ensure _ir_info is generated

abi = module_t.interface.to_toplevel_abi_dict()
Expand Down
10 changes: 5 additions & 5 deletions vyper/compiler/phases.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class CompilerData:
----------
vyper_module : vy_ast.Module
Top-level Vyper AST node
vyper_module_annotated : vy_ast.Module
Annotated Vyper AST
annotated_vyper_module: vy_ast.Module
Annotated/analysed Vyper AST
global_ctx : ModuleT
Sorted, contextualized representation of the Vyper AST
ir_nodes : IRnode
Expand Down Expand Up @@ -158,7 +158,7 @@ def _annotated_module(self):
)

@property
def vyper_module_annotated(self) -> vy_ast.Module:
def annotated_vyper_module(self) -> vy_ast.Module:
module, storage_layout = self._annotated_module
return module

Expand All @@ -169,7 +169,7 @@ def storage_layout(self) -> StorageLayout:

@property
def global_ctx(self) -> ModuleT:
return self.vyper_module_annotated._metadata["type"]
return self.annotated_vyper_module._metadata["type"]

@cached_property
def _ir_output(self):
Expand Down Expand Up @@ -198,7 +198,7 @@ def function_signatures(self) -> dict[str, ContractFunctionT]:
# ensure codegen is run:
_ = self._ir_output

fs = self.vyper_module_annotated.get_children(vy_ast.FunctionDef)
fs = self.annotated_vyper_module.get_children(vy_ast.FunctionDef)
return {f.name: f._metadata["func_type"] for f in fs}

@cached_property
Expand Down

0 comments on commit 580bd89

Please sign in to comment.