def parse_Call(self): from vyper.functions import DISPATCH_TABLE if isinstance(self.expr.func, vy_ast.Name): function_name = self.expr.func.id if function_name in DISPATCH_TABLE: return DISPATCH_TABLE[function_name].build_LLL( self.expr, self.context) # Struct constructors do not need `self` prefix. elif function_name in self.context.structs: args = self.expr.args if len(args) == 1 and isinstance(args[0], vy_ast.Dict): return Expr.struct_literals(args[0], function_name, self.context) # Interface assignment. Bar(<address>). elif function_name in self.context.sigs: ret, arg_lll = self._is_valid_interface_assign() if ret is True: arg_lll.typ = InterfaceType( function_name) # Cast to Correct interface type. return arg_lll elif (isinstance(self.expr.func, vy_ast.Attribute) and isinstance(self.expr.func.value, vy_ast.Name) and self.expr.func.value.id == "self"): # noqa: E501 return self_call.make_call(self.expr, self.context) else: return external_call.make_external_call(self.expr, self.context)
def call(self): from vyper.functions import ( dispatch_table, ) if isinstance(self.expr.func, ast.Name): function_name = self.expr.func.id if function_name in dispatch_table: return dispatch_table[function_name](self.expr, self.context) # Struct constructors do not need `self` prefix. elif function_name in self.context.structs: args = self.expr.args if len(args) != 1: raise StructureException("Struct constructor is called with one argument only", self.expr) arg = args[0] if not isinstance(arg, ast.Dict): raise TypeMismatchException("Struct can only be constructed with a dict", self.expr) return Expr.struct_literals(arg, function_name, self.context) else: err_msg = "Not a top-level function: {}".format(function_name) if function_name in [x.split('(')[0] for x, _ in self.context.sigs['self'].items()]: err_msg += ". Did you mean self.{}?".format(function_name) raise StructureException(err_msg, self.expr) elif isinstance(self.expr.func, ast.Attribute) and isinstance(self.expr.func.value, ast.Name) and self.expr.func.value.id == "self": return self_call.make_call(self.expr, self.context) else: return external_call.make_external_call(self.expr, self.context)
def call(self): from vyper.functions import ( DISPATCH_TABLE, ) if isinstance(self.expr.func, vy_ast.Name): function_name = self.expr.func.id if function_name in DISPATCH_TABLE: return DISPATCH_TABLE[function_name].build_LLL( self.expr, self.context) # Struct constructors do not need `self` prefix. elif function_name in self.context.structs: args = self.expr.args if len(args) != 1: raise StructureException( "Struct constructor is called with one argument only", self.expr, ) arg = args[0] if not isinstance(arg, vy_ast.Dict): raise TypeMismatch( "Struct can only be constructed with a dict", self.expr, ) return Expr.struct_literals(arg, function_name, self.context) # Contract assignment. Bar(<address>). elif function_name in self.context.sigs: ret, arg_lll = self._is_valid_contract_assign() if ret is True: arg_lll.typ = ContractType( function_name) # Cast to Correct contract type. return arg_lll else: raise TypeMismatch( "ContractType definition expects one address argument.", self.expr, ) else: err_msg = f"Not a top-level function: {function_name}" if function_name in [ x.split('(')[0] for x, _ in self.context.sigs['self'].items() ]: err_msg += f". Did you mean self.{function_name}?" raise StructureException(err_msg, self.expr) elif isinstance(self.expr.func, vy_ast.Attribute) and isinstance( self.expr.func.value, vy_ast.Name ) and self.expr.func.value.id == "self": # noqa: E501 return self_call.make_call(self.expr, self.context) else: return external_call.make_external_call(self.expr, self.context)
def parse_Call(self): is_self_function = ((isinstance(self.stmt.func, vy_ast.Attribute)) and isinstance(self.stmt.func.value, vy_ast.Name) and self.stmt.func.value.id == "self") if isinstance(self.stmt.func, vy_ast.Name): funcname = self.stmt.func.id return STMT_DISPATCH_TABLE[funcname].build_LLL( self.stmt, self.context) elif is_self_function: return self_call.make_call(self.stmt, self.context) else: return external_call.make_external_call(self.stmt, self.context)
def call(self): from .parser import ( pack_logging_data, pack_logging_topics, ) if isinstance(self.stmt.func, ast.Name): if self.stmt.func.id in stmt_dispatch_table: if self.stmt.func.id == 'clear': return self._clear() else: return stmt_dispatch_table[self.stmt.func.id](self.stmt, self.context) elif self.stmt.func.id in dispatch_table: raise StructureException("Function {} can not be called without being used.".format(self.stmt.func.id), self.stmt) else: raise StructureException("Unknown function: '{}'.".format(self.stmt.func.id), self.stmt) elif isinstance(self.stmt.func, ast.Attribute) and isinstance(self.stmt.func.value, ast.Name) and self.stmt.func.value.id == "self": return self_call.make_call(self.stmt, self.context) elif isinstance(self.stmt.func, ast.Attribute) and isinstance(self.stmt.func.value, ast.Name) and self.stmt.func.value.id == 'log': if self.stmt.func.attr not in self.context.sigs['self']: raise EventDeclarationException("Event not declared yet: %s" % self.stmt.func.attr) event = self.context.sigs['self'][self.stmt.func.attr] if len(event.indexed_list) != len(self.stmt.args): raise EventDeclarationException("%s received %s arguments but expected %s" % (event.name, len(self.stmt.args), len(event.indexed_list))) expected_topics, topics = [], [] expected_data, data = [], [] for pos, is_indexed in enumerate(event.indexed_list): if is_indexed: expected_topics.append(event.args[pos]) topics.append(self.stmt.args[pos]) else: expected_data.append(event.args[pos]) data.append(self.stmt.args[pos]) topics = pack_logging_topics(event.event_id, topics, expected_topics, self.context, pos=getpos(self.stmt)) inargs, inargsize, inargsize_node, inarg_start = pack_logging_data(expected_data, data, self.context, pos=getpos(self.stmt)) if inargsize_node is None: sz = inargsize else: sz = ['mload', inargsize_node] return LLLnode.from_list(['seq', inargs, LLLnode.from_list(["log" + str(len(topics)), inarg_start, sz] + topics, add_gas_estimate=inargsize * 10)], typ=None, pos=getpos(self.stmt)) else: return external_call.make_external_call(self.stmt, self.context)
def call(self): is_self_function = (isinstance( self.stmt.func, ast.Attribute)) and isinstance( self.stmt.func.value, ast.Name) and self.stmt.func.value.id == "self" is_log_call = (isinstance( self.stmt.func, ast.Attribute)) and isinstance( self.stmt.func.value, ast.Name) and self.stmt.func.value.id == 'log' if isinstance(self.stmt.func, ast.Name): if self.stmt.func.id in STMT_DISPATCH_TABLE: if self.stmt.func.id == 'clear': return self._clear() else: return STMT_DISPATCH_TABLE[self.stmt.func.id](self.stmt, self.context) elif self.stmt.func.id in DISPATCH_TABLE: raise StructureException( f"Function {self.stmt.func.id} can not be called without being used.", self.stmt, ) else: raise StructureException( f"Unknown function: '{self.stmt.func.id}'.", self.stmt, ) elif is_self_function: return self_call.make_call(self.stmt, self.context) elif is_log_call: if self.stmt.func.attr not in self.context.sigs['self']: raise EventDeclarationException( f"Event not declared yet: {self.stmt.func.attr}") event = self.context.sigs['self'][self.stmt.func.attr] if len(event.indexed_list) != len(self.stmt.args): raise EventDeclarationException( f"{event.name} received {len(self.stmt.args)} arguments but " f"expected {len(event.indexed_list)}") expected_topics, topics = [], [] expected_data, data = [], [] for pos, is_indexed in enumerate(event.indexed_list): if is_indexed: expected_topics.append(event.args[pos]) topics.append(self.stmt.args[pos]) else: expected_data.append(event.args[pos]) data.append(self.stmt.args[pos]) topics = pack_logging_topics( event.event_id, topics, expected_topics, self.context, pos=getpos(self.stmt), ) inargs, inargsize, inargsize_node, inarg_start = pack_logging_data( expected_data, data, self.context, pos=getpos(self.stmt), ) if inargsize_node is None: sz = inargsize else: sz = ['mload', inargsize_node] return LLLnode.from_list([ 'seq', inargs, LLLnode.from_list( ["log" + str(len(topics)), inarg_start, sz] + topics, add_gas_estimate=inargsize * 10, ) ], typ=None, pos=getpos(self.stmt)) else: return external_call.make_external_call(self.stmt, self.context)
def call(self): from vyper.functions import ( dispatch_table, ) if isinstance(self.expr.func, ast.Name): function_name = self.expr.func.id if function_name in dispatch_table: return dispatch_table[function_name](self.expr, self.context) # Struct constructors do not need `self` prefix. elif function_name in self.context.structs: if not self.context.in_assignment: raise StructureException( "Struct constructor must be called in RHS of assignment.", self.expr) args = self.expr.args if len(args) != 1: raise StructureException( "Struct constructor is called with one argument only", self.expr) arg = args[0] if not isinstance(arg, ast.Dict): raise TypeMismatchException( "Struct can only be constructed with a dict", self.expr) sub = Expr.struct_literals(arg, self.context) if sub.typ.name is not None: raise TypeMismatchException( "Struct can only be constructed with a dict", self.expr) typ = StructType(sub.typ.members, function_name) # OR: # sub.typ = typ # return sub return LLLnode(sub.value, typ=typ, args=sub.args, location=sub.location, pos=getpos(self.expr), add_gas_estimate=sub.add_gas_estimate, valency=sub.valency, annotation=function_name) else: err_msg = "Not a top-level function: {}".format(function_name) if function_name in [ x.split('(')[0] for x, _ in self.context.sigs['self'].items() ]: err_msg += ". Did you mean self.{}?".format(function_name) raise StructureException(err_msg, self.expr) elif isinstance(self.expr.func, ast.Attribute) and isinstance( self.expr.func.value, ast.Name) and self.expr.func.value.id == "self": return self_call.make_call(self.expr, self.context) else: return external_call.make_external_call(self.expr, self.context)