1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::{
prelude::*,
runtime::cache::shared_references_cache::SharedReferencesCache,
shared_values::PointerAddress,
types::entity_type::EntityType,
values::value::value_classification::{
ValueClassification, ValueTag,
unresolved_value_classification::UnresolvedValueClassification,
},
};
pub trait Classification {
/// Returns the DATEX [EntityType] of the native value if it has an entity type.
/// For structural types, this will return None.
/// The default implementation returns None, indicating that the value does not have an entity type.
fn entity_type(
&self,
_cache: &mut SharedReferencesCache,
) -> Option<EntityType> {
None
}
/// Returns the [PointerAddress] of the entity type if it has one.
/// The default implementation returns None, indicating that the value does not have an entity type address.
/// It must be ensured that the entity type for the given address is already registered in the runtime.
fn entity_type_address(&self) -> Option<PointerAddress> {
None
}
/// Returns a [ValueTag] if the value has a tag.
/// The default implementation returns None, indicating that the value does not have a tag.
fn tag(&self) -> Option<ValueTag> {
None
}
/// Returns a list of [PointerAddress]es of the impls associated with the value.
/// The default implementation returns an empty list, indicating that the value does not have any impls.
fn impls(&self) -> Vec<PointerAddress> {
Vec::new()
}
/// Returns the DATEX [ValueClassification] of the native value.
/// This tries to resolve the entity type and tag, assuming at most one of them is present.
fn classification(
&self,
cache: &mut SharedReferencesCache,
) -> ValueClassification {
let impls = self.impls();
let entity_type = self.entity_type(cache);
let tag = self.tag();
ValueClassification {
entity_type,
impls,
tag,
}
}
/// Returns the unresolved DATEX [UnresolvedValueClassification] of the native value.
/// This does not try to resolve the entity, but instead returns the address of the entity type if it has one.
fn unresolved_classification(&self) -> UnresolvedValueClassification {
let impls = self.impls();
let entity_type_address = self.entity_type_address();
let tag = self.tag();
UnresolvedValueClassification {
entity_type_address,
impls,
tag,
}
}
}