lisette_syntax/program/
resolution.rs1use rustc_hash::FxHashMap as HashMap;
2
3use crate::ast::{Expression, Span};
4use crate::types::Symbol;
5use crate::types::Type;
6
7pub type ResolvedDefinitions = HashMap<Span, Symbol>;
8
9pub fn resolved_definition<'a>(
10 expression: &'a Expression,
11 definitions: &'a ResolvedDefinitions,
12) -> Option<&'a str> {
13 match expression.unwrap_parens() {
14 Expression::Identifier {
15 qualified: Some(definition),
16 ..
17 } => Some(definition),
18 Expression::DotAccess { span, .. } => definitions.get(span).map(Symbol::as_str),
19 _ => None,
20 }
21}
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24pub enum ReceiverCoercion {
25 AutoAddress,
27 AutoDeref,
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
33pub enum DotAccessKind {
34 StructField { is_exported: bool },
36 TupleStructField { is_newtype: bool },
40 TupleElement,
42 ModuleMember,
44 EnumVariant,
46 InstanceMethod { is_exported: bool },
48 InstanceMethodValue {
52 is_exported: bool,
53 is_pointer_receiver: bool,
54 },
55 StaticMethod { is_exported: bool },
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq)]
63pub enum NativeTypeKind {
64 Slice,
65 EnumeratedSlice,
66 Map,
67 Channel,
68 Sender,
69 Receiver,
70 String,
71 Array,
72}
73
74impl NativeTypeKind {
75 pub fn from_type(ty: &Type) -> Option<Self> {
76 let resolved = ty.strip_refs();
77 if resolved.as_import_namespace().is_some() {
80 return None;
81 }
82 if let Type::Nominal { ref id, .. } = resolved
83 && id.as_str().starts_with("go:")
84 {
85 return None;
86 }
87 let name = resolved.get_name()?;
88 Self::from_name(name)
89 }
90
91 pub fn from_name(name: &str) -> Option<Self> {
92 match name {
93 "Slice" => Some(Self::Slice),
94 "EnumeratedSlice" => Some(Self::EnumeratedSlice),
95 "Map" => Some(Self::Map),
96 "Channel" => Some(Self::Channel),
97 "Sender" => Some(Self::Sender),
98 "Receiver" => Some(Self::Receiver),
99 "string" => Some(Self::String),
100 "Array" => Some(Self::Array),
101 _ => None,
102 }
103 }
104}
105
106#[derive(Debug, Clone, Copy, PartialEq, Eq)]
108pub enum CallKind {
109 Regular,
111 TupleStructConstructor,
113 AssertType,
115 UfcsMethod,
117 NativeConstructor(NativeTypeKind),
119 NativeMethod(NativeTypeKind),
121 NativeMethodIdentifier(NativeTypeKind),
123 ReceiverMethodUfcs { is_public: bool },
125}