use crate::{
decl_engine::DeclRef, engine_threading::*, language::parsed, transform, type_system::*,
};
use std::hash::{Hash, Hasher};
use sway_types::{Ident, Span, Spanned};
#[derive(Clone, Debug)]
pub struct TyAbiDeclaration {
pub name: Ident,
pub interface_surface: Vec<DeclRef>,
pub supertraits: Vec<parsed::Supertrait>,
pub methods: Vec<DeclRef>,
pub span: Span,
pub attributes: transform::AttributesMap,
}
impl EqWithEngines for TyAbiDeclaration {}
impl PartialEqWithEngines for TyAbiDeclaration {
fn eq(&self, other: &Self, engines: Engines<'_>) -> bool {
self.name == other.name
&& self.interface_surface.eq(&other.interface_surface, engines)
&& self.methods.eq(&other.methods, engines)
}
}
impl HashWithEngines for TyAbiDeclaration {
fn hash<H: Hasher>(&self, state: &mut H, engines: Engines<'_>) {
let TyAbiDeclaration {
name,
interface_surface,
methods,
supertraits,
attributes: _,
span: _,
} = self;
name.hash(state);
interface_surface.hash(state, engines);
methods.hash(state, engines);
supertraits.hash(state, engines);
}
}
impl CreateTypeId for TyAbiDeclaration {
fn create_type_id(&self, engines: Engines<'_>) -> TypeId {
let type_engine = engines.te();
let decl_engine = engines.de();
let ty = TypeInfo::ContractCaller {
abi_name: AbiName::Known(self.name.clone().into()),
address: None,
};
type_engine.insert(decl_engine, ty)
}
}
impl Spanned for TyAbiDeclaration {
fn span(&self) -> Span {
self.span.clone()
}
}