How to use the vyper.parser.parser_utils.getpos function in vyper

To help you get started, we’ve selected a few vyper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vyperlang / vyper / vyper / functions / functions.py View on Github external
def bitwise_or(expr, args, kwargs, context):
    return LLLnode.from_list(['or', args[0], args[1]], typ=BaseType('uint256'), pos=getpos(expr))
github Neroysq / VyperFlow / vyper / parser / parser.py View on Github external
_func_augs[_def.name][1] = _func_augs_backup

    elif isinstance(node, ast.AnnAssign) :
        l_var = pc + "." + node.target.id
        pos = getpos(node)
        if isinstance(node.annotation, ast.Call) and node.annotation.func.id == "IFL":
            IFLs[l_var] = {"pos" : pos, "const" : True} #TODO: const?
            if_label, IFLs = IF_utils.eval_label(node.annotation.args[1], IFLs)
            _cons.append(IF_utils.new_cons(if_label, l_var, pos))
        else :
            IFLs[l_var] = {"pos" : pos, "const" : False}

        if node.value is not None :
            l_result, _cons, IFLs = if_parse_expr(node.value, _func_augs, _cons, IFLs, _def, pc)
            _cons.append(IF_utils.new_cons(l_var, l_result, getpos(node.value)))
        _cons.append(IF_utils.new_cons(l_var, pc, pos))
        _func_augs[_def.name][1][node.target.id] = l_var

    elif isinstance(node, ast.AugAssign) :
        lbl, _cons, IFLs = if_parse_expr(node.target, _func_augs, _cons, IFLs, _def, pc)
        l_result, _cons, IFLs = if_parse_expr(node.value, _func_augs, _cons, IFLs, _def, pc)
        _cons.append(IF_utils.new_cons(lbl, l_result, getpos(node)))
        _cons.append(IF_utils.new_cons(lbl, pc, getpos(node)))

    elif isinstance(node, ast.Break) :
        pass

    elif isinstance(node, ast.Continue) :
        pass

    elif isinstance(node, ast.Return) :
github vyperlang / vyper / vyper / parser / expr.py View on Github external
def _make_bytelike(self, btype, bytez, bytez_length):
        placeholder = self.context.new_placeholder(btype)
        seq = []
        seq.append(['mstore', placeholder, bytez_length])
        for i in range(0, len(bytez), 32):
            seq.append([
                'mstore',
                ['add', placeholder, i + 32],
                bytes_to_int((bytez + b'\x00' * 31)[i: i + 32])
            ])
        return LLLnode.from_list(
            ['seq'] + seq + [placeholder],
            typ=btype,
            location='memory',
            pos=getpos(self.expr),
            annotation=f'Create {btype}: {bytez}',
        )
github vyperlang / vyper / vyper / parser / function_definitions / parse_private_function.py View on Github external
sig_chain,
                [
                    'if', 0,  # can only be jumped into
                    [
                        'seq',
                        ['seq'] + nonreentrant_pre + _clampers + [
                            parse_body(c, context)
                            for c in code.body
                        ] + nonreentrant_post + stop_func
                    ],
                ],
            ], typ=None, pos=getpos(code))

    else:
        # Function without default parameters.
        sig_compare, private_label = get_sig_statements(sig, getpos(code))
        o = LLLnode.from_list(
            [
                'if',
                sig_compare,
                ['seq'] + [private_label] + nonreentrant_pre + clampers + [
                    parse_body(c, context)
                    for c
                    in code.body
                ] + nonreentrant_post + stop_func
            ], typ=None, pos=getpos(code)
        )
        return o

    return o
github vyperlang / vyper / vyper / parser / stmt.py View on Github external
def parse_return(self):
        if self.context.return_type is None:
            if self.stmt.value:
                raise TypeMismatchException("Not expecting to return a value", self.stmt)
            return LLLnode.from_list(
                make_return_stmt(self.stmt, self.context, 0, 0),
                typ=None,
                pos=getpos(self.stmt),
                valency=0,
            )
        if not self.stmt.value:
            raise TypeMismatchException("Expecting to return a value", self.stmt)

        sub = Expr(self.stmt.value, self.context).lll_node

        # Returning a value (most common case)
        if isinstance(sub.typ, BaseType):
            sub = unwrap_location(sub)

            if not isinstance(self.context.return_type, BaseType):
                raise TypeMismatchException(
                    f"Return type units mismatch {sub.typ} {self.context.return_type}",
                    self.stmt.value
                )
github Neroysq / VyperFlow / vyper / parser / parser.py View on Github external
_getters[-1].pos = getpos(item)
    elif isinstance(item.annotation, ast.Call) and item.annotation.func.id == "public":
        if isinstance(item.annotation.args[0], ast.Name) and item_name in _contracts:
            typ = ContractType(item_name)
        else:
            typ = parse_type(item.annotation.args[0], 'storage', custom_units=_custom_units)
        if "IFL" not in item_attributes :
            IFLs, _cons = if_new_global_variable(item.target.id, getpos(item), None, IFLs, _cons)
            #raise VariableDeclarationException("Variable %s declared without information flow label", item.target.id)
        else :
            IFLs, _cons = if_new_global_variable(item.target.id, getpos(item), item_attributes["IFL"], IFLs, _cons)
        _globals[item.target.id] = VariableRecord(item.target.id, len(_globals), typ, True)
        # Adding getters here
        for getter in mk_getter(item.target.id, typ):
            _getters.append(parse_line('\n' * (item.lineno - 1) + getter))
            _getters[-1].pos = getpos(item)
    else:
        if "IFL" not in item_attributes :
            IFLs, _cons = if_new_global_variable(item.target.id, getpos(item), None, IFLs, _cons)
            #raise VariableDeclarationException("Variable %s declared without information flow label", item.target.id)
        else :
            IFLs, _cons = if_new_global_variable(item.target.id, getpos(item), item_attributes["IFL"], IFLs, _cons)
        _globals[item.target.id] = VariableRecord(
            item.target.id, len(_globals),
            parse_type(item.annotation, 'storage', custom_units=_custom_units),
            True
        )
    return _custom_units, _contracts, _events, _globals, _getters, IFLs, _cons
github vyperlang / vyper / vyper / parser / stmt.py View on Github external
)

            is_literal_bytes32_assign = (
                isinstance(sub.typ, ByteArrayType)
                and sub.typ.maxlen == 32
                and isinstance(typ, BaseType)
                and typ.typ == 'bytes32'
                and sub.typ.is_literal
            )

            # If bytes[32] to bytes32 assignment rewrite sub as bytes32.
            if is_literal_bytes32_assign:
                sub = LLLnode(
                    bytes_to_int(self.stmt.value.s),
                    typ=BaseType('bytes32'),
                    pos=getpos(self.stmt),
                )

            self._check_valid_assign(sub)
            self._check_same_variable_assign(sub)
            variable_loc = LLLnode.from_list(
                pos,
                typ=typ,
                location='memory',
                pos=getpos(self.stmt),
            )
            o = make_setter(variable_loc, sub, 'memory', pos=getpos(self.stmt))
            # o.pos = getpos(self.stmt) # TODO: Should this be here like in assign()?

            return o
github vyperlang / vyper / vyper / parser / expr.py View on Github external
raise TypeMismatchException(
                f"{left.typ} cannot be in a list of {right.typ.subtype}",
            )

        result_placeholder = self.context.new_placeholder(BaseType('bool'))
        setter = []

        # Load nth item from list in memory.
        if right.value == 'multi':
            # Copy literal to memory to be compared.
            tmp_list = LLLnode.from_list(
                obj=self.context.new_placeholder(ListType(right.typ.subtype, right.typ.count)),
                typ=ListType(right.typ.subtype, right.typ.count),
                location='memory'
            )
            setter = make_setter(tmp_list, right, 'memory', pos=getpos(self.expr))
            load_i_from_list = [
                'mload',
                ['add', tmp_list, ['mul', 32, ['mload', MemoryPositions.FREE_LOOP_INDEX]]],
            ]
        elif right.location == "storage":
            load_i_from_list = [
                'sload',
                ['add', ['sha3_32', right], ['mload', MemoryPositions.FREE_LOOP_INDEX]],
            ]
        else:
            load_i_from_list = [
                'mload',
                ['add', right, ['mul', 32, ['mload', MemoryPositions.FREE_LOOP_INDEX]]],
            ]

        # Condition repeat loop has to break on.
github vyperlang / vyper / vyper / functions / functions.py View on Github external
def ecmul(expr, args, kwargs, context):
    placeholder_node = LLLnode.from_list(
        context.new_placeholder(ByteArrayType(128)), typ=ByteArrayType(128), location='memory'
    )
    pos = getpos(expr)
    o = LLLnode.from_list([
        'seq',
        ['mstore', placeholder_node, avo(args[0], 0, pos)],
        ['mstore', ['add', placeholder_node, 32], avo(args[0], 1, pos)],
        ['mstore', ['add', placeholder_node, 64], args[1]],
        ['assert', ['call', ['gas'], 7, 0, placeholder_node, 96, placeholder_node, 64]],
        placeholder_node,
    ], typ=ListType(BaseType('uint256'), 2), pos=pos, location='memory')
    return o
github vyperlang / vyper / vyper / parser / stmt.py View on Github external
def parse_pass(self):
        return LLLnode.from_list('pass', typ=None, pos=getpos(self.stmt))