示例#1
0
def generate_folded_ast(
    vyper_module: vy_ast.Module,
    interface_codes: Optional[InterfaceImports],
    storage_layout_overrides: StorageLayout = None,
) -> Tuple[vy_ast.Module, StorageLayout]:
    """
    Perform constant folding operations on the Vyper AST.

    Arguments
    ---------
    vyper_module : vy_ast.Module
        Top-level Vyper AST node

    Returns
    -------
    vy_ast.Module
        Folded Vyper AST
    StorageLayout
        Layout of variables in storage
    """
    vy_ast.validation.validate_literal_nodes(vyper_module)

    vyper_module_folded = copy.deepcopy(vyper_module)
    vy_ast.folding.fold(vyper_module_folded)
    validate_semantics(vyper_module_folded, interface_codes)
    vy_ast.expansion.expand_annotated_ast(vyper_module_folded)
    symbol_tables = set_data_positions(vyper_module_folded,
                                       storage_layout_overrides)

    return vyper_module_folded, symbol_tables
示例#2
0
def generate_folded_ast(
        vyper_module: vy_ast.Module,
        interface_codes: Optional[InterfaceImports]) -> vy_ast.Module:
    """
    Perform constant folding operations on the Vyper AST.

    Arguments
    ---------
    vyper_module : vy_ast.Module
        Top-level Vyper AST node

    Returns
    -------
    vy_ast.Module
        Folded Vyper AST
    """
    vy_ast.validation.validate_literal_nodes(vyper_module)

    vyper_module_folded = copy.deepcopy(vyper_module)
    vy_ast.folding.fold(vyper_module_folded)
    validate_semantics(vyper_module_folded, interface_codes)
    vy_ast.expansion.expand_annotated_ast(vyper_module_folded)
    set_data_positions(vyper_module_folded)

    return vyper_module_folded
示例#3
0
文件: phases.py 项目: fubuloubu/vyper
def generate_unfolded_ast(
        vyper_module: vy_ast.Module,
        interface_codes: Optional[InterfaceImports]) -> vy_ast.Module:

    vy_ast.validation.validate_literal_nodes(vyper_module)
    vy_ast.folding.replace_builtin_constants(vyper_module)
    vy_ast.folding.replace_builtin_functions(vyper_module)
    # note: validate_semantics does type inference on the AST
    validate_semantics(vyper_module, interface_codes)

    return vyper_module
示例#4
0
def test_invalid_checksum(code):
    vyper_module = vy_ast.parse_to_ast(code)

    with pytest.raises(InvalidLiteral):
        vy_ast.validation.validate_literal_nodes(vyper_module)
        semantics.validate_semantics(vyper_module, {})