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_constructor_path(path: &str) -> Option<Self> {
92 match path {
93 "Channel.new" | "Channel.buffered" => Some(Self::Channel),
94 "Map.new" => Some(Self::Map),
95 "Slice.new" | "Slice.make" => Some(Self::Slice),
96 _ => None,
97 }
98 }
99
100 pub fn is_constructor_method(name: &str) -> bool {
101 matches!(name, "new" | "buffered" | "make")
102 }
103
104 pub fn from_name(name: &str) -> Option<Self> {
105 match name {
106 "Slice" => Some(Self::Slice),
107 "EnumeratedSlice" => Some(Self::EnumeratedSlice),
108 "Map" => Some(Self::Map),
109 "Channel" => Some(Self::Channel),
110 "Sender" => Some(Self::Sender),
111 "Receiver" => Some(Self::Receiver),
112 "string" => Some(Self::String),
113 "Array" => Some(Self::Array),
114 _ => None,
115 }
116 }
117}
118
119#[derive(Debug, Clone, Copy, PartialEq, Eq)]
121pub enum CallKind {
122 Regular,
124 TupleStructConstructor,
126 AssertType,
128 UfcsMethod,
130 NativeConstructor(NativeTypeKind),
132 NativeMethod(NativeTypeKind),
134 NativeMethodIdentifier(NativeTypeKind),
136 ReceiverMethodUfcs { is_public: bool },
138}