def visitAnnotatedTypeName(self, ast: AnnotatedTypeName): if type(ast.type_name) == UserDefinedTypeName: if not isinstance(ast.type_name.target, EnumDefinition): raise TypeException('Unsupported use of user-defined type', ast.type_name) ast.type_name = ast.type_name.target.annotated_type.type_name.clone( ) if ast.privacy_annotation != Expression.all_expr(): if not ast.type_name.can_be_private(): raise TypeException( f'Currently, we do not support private {str(ast.type_name)}', ast) p = ast.privacy_annotation if isinstance(p, IdentifierExpr): t = p.target if isinstance(t, Mapping): # no action necessary, this is the case: mapping(address!x => uint@x) pass elif not t.is_final and not t.is_constant: raise TypeException( 'Privacy annotations must be "final" or "constant", if they are expressions', p) elif t.annotated_type != AnnotatedTypeName.address_all(): raise TypeException( f'Privacy type is not a public address, but {str(t.annotated_type)}', p)
def visitAnnotatedTypeName(self, ast: AnnotatedTypeName): if type(ast.type_name) == UserDefinedTypeName: if not isinstance(ast.type_name.target, EnumDefinition): raise TypeException('Unsupported use of user-defined type', ast.type_name) ast.type_name = ast.type_name.target.annotated_type.type_name.clone( ) if ast.privacy_annotation != Expression.all_expr(): if not ast.type_name.can_be_private(): raise TypeException( f'Currently, we do not support private {str(ast.type_name)}', ast) if ast.homomorphism != Homomorphism.NON_HOMOMORPHIC: # only support uint8, uint16, uint24, uint32 homomorphic data types if not ast.type_name.is_numeric: raise TypeException( f'Homomorphic type not supported for {str(ast.type_name)}: Only numeric types supported', ast) elif ast.type_name.signed: raise TypeException( f'Homomorphic type not supported for {str(ast.type_name)}: Only unsigned types supported', ast) elif ast.type_name.elem_bitwidth > 32: raise TypeException( f'Homomorphic type not supported for {str(ast.type_name)}: Only up to 32-bit numeric types supported', ast) p = ast.privacy_annotation if isinstance(p, IdentifierExpr): t = p.target if isinstance(t, Mapping): # no action necessary, this is the case: mapping(address!x => uint@x) pass elif not t.is_final and not t.is_constant: raise TypeException( 'Privacy annotations must be "final" or "constant", if they are expressions', p) elif t.annotated_type != AnnotatedTypeName.address_all(): raise TypeException( f'Privacy type is not a public address, but {str(t.annotated_type)}', p)
def visitMeExpr(ast: MeExpr): """Replace me with msg.sender.""" return replace_expr(ast, IdentifierExpr('msg').dot('sender')).as_type(AnnotatedTypeName.address_all())
def visitMeExpr(self, ast: MeExpr): ast.annotated_type = AnnotatedTypeName.address_all()