mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-24 20:42:29 +00:00
moved all crates into seperate folder + related path fixes
This commit is contained in:
parent
12ef03bb86
commit
eee85fa45d
1063 changed files with 92 additions and 93 deletions
113
crates/compiler/can/src/expected.rs
Normal file
113
crates/compiler/can/src/expected.rs
Normal file
|
@ -0,0 +1,113 @@
|
|||
use crate::pattern::Pattern;
|
||||
use roc_region::all::{Loc, Region};
|
||||
use roc_types::types::{AnnotationSource, PReason, Reason};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Expected<T> {
|
||||
NoExpectation(T),
|
||||
FromAnnotation(Loc<Pattern>, usize, AnnotationSource, T),
|
||||
ForReason(Reason, T, Region),
|
||||
}
|
||||
|
||||
/// Like Expected, but for Patterns.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PExpected<T> {
|
||||
NoExpectation(T),
|
||||
ForReason(PReason, T, Region),
|
||||
}
|
||||
|
||||
impl<T> PExpected<T> {
|
||||
pub fn get_type(self) -> T {
|
||||
match self {
|
||||
PExpected::NoExpectation(val) => val,
|
||||
PExpected::ForReason(_, val, _) => val,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_type_ref(&self) -> &T {
|
||||
match self {
|
||||
PExpected::NoExpectation(val) => val,
|
||||
PExpected::ForReason(_, val, _) => val,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_type_mut_ref(&mut self) -> &mut T {
|
||||
match self {
|
||||
PExpected::NoExpectation(val) => val,
|
||||
PExpected::ForReason(_, val, _) => val,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn replace<U>(self, new: U) -> PExpected<U> {
|
||||
match self {
|
||||
PExpected::NoExpectation(_val) => PExpected::NoExpectation(new),
|
||||
PExpected::ForReason(reason, _val, region) => PExpected::ForReason(reason, new, region),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn replace_ref<U>(&self, new: U) -> PExpected<U> {
|
||||
match self {
|
||||
PExpected::NoExpectation(_val) => PExpected::NoExpectation(new),
|
||||
PExpected::ForReason(reason, _val, region) => {
|
||||
PExpected::ForReason(reason.clone(), new, *region)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Expected<T> {
|
||||
pub fn get_type(self) -> T {
|
||||
match self {
|
||||
Expected::NoExpectation(val) => val,
|
||||
Expected::ForReason(_, val, _) => val,
|
||||
Expected::FromAnnotation(_, _, _, val) => val,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_type_ref(&self) -> &T {
|
||||
match self {
|
||||
Expected::NoExpectation(val) => val,
|
||||
Expected::ForReason(_, val, _) => val,
|
||||
Expected::FromAnnotation(_, _, _, val) => val,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_type_mut_ref(&mut self) -> &mut T {
|
||||
match self {
|
||||
Expected::NoExpectation(val) => val,
|
||||
Expected::ForReason(_, val, _) => val,
|
||||
Expected::FromAnnotation(_, _, _, val) => val,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_annotation_region(&self) -> Option<Region> {
|
||||
match self {
|
||||
Expected::FromAnnotation(_, _, AnnotationSource::TypedBody { region }, _) => {
|
||||
Some(*region)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn replace<U>(self, new: U) -> Expected<U> {
|
||||
match self {
|
||||
Expected::NoExpectation(_val) => Expected::NoExpectation(new),
|
||||
Expected::ForReason(reason, _val, region) => Expected::ForReason(reason, new, region),
|
||||
Expected::FromAnnotation(pattern, size, source, _val) => {
|
||||
Expected::FromAnnotation(pattern, size, source, new)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn replace_ref<U>(&self, new: U) -> Expected<U> {
|
||||
match self {
|
||||
Expected::NoExpectation(_val) => Expected::NoExpectation(new),
|
||||
Expected::ForReason(reason, _val, region) => {
|
||||
Expected::ForReason(reason.clone(), new, *region)
|
||||
}
|
||||
Expected::FromAnnotation(pattern, size, source, _val) => {
|
||||
Expected::FromAnnotation(pattern.clone(), *size, *source, new)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue