|
1 | | -use super::helper::prelude::*; |
| 1 | +use super::helper::{prelude::*, transform_key::*}; |
2 | 2 | use crate::{cache, semantics, utils::naming::sanitize, Error}; |
3 | | -use semantics::{analyze::*, Event, Kind, Transition}; |
| 3 | +use semantics::{analyze::*, Kind, Transition}; |
4 | 4 |
|
5 | 5 | impl SemanticCheck for Transition<'_> { |
6 | 6 | fn check_error(&self) -> Result<Option<String>, Error> { |
@@ -52,63 +52,6 @@ impl SemanticCheck for Transition<'_> { |
52 | 52 | } |
53 | 53 | } |
54 | 54 |
|
55 | | -// WARNING: not performant because of using concatenated String as a key which cause filtering |
56 | | -impl From<&Event<'_>> for String { |
57 | | - fn from(event: &Event<'_>) -> Self { |
58 | | - format!("{}?{}", event.name.unwrap_or(""), event.guard.unwrap_or("")) |
59 | | - } |
60 | | -} |
61 | | - |
62 | | -impl<'i> EventKey<'i> for &'i Option<String> {} |
63 | | -trait EventKey<'i>: Into<Option<&'i String>> { |
64 | | - fn has_trigger(self) -> bool { |
65 | | - self.into().filter(|e| is_empty(e.rsplit('?'))).is_some() |
66 | | - } |
67 | | - fn has_guard(self) -> bool { |
68 | | - self.into().filter(|e| is_empty(e.split('?'))).is_some() |
69 | | - } |
70 | | - fn get_guard(self) -> Option<&'i str> { |
71 | | - self.into().and_then(|e| none_empty(e.split('?'))) |
72 | | - } |
73 | | - fn get_trigger(self) -> Option<&'i str> { |
74 | | - self.into().and_then(|e| none_empty(e.rsplit('?'))) |
75 | | - } |
76 | | - fn guards_with_same_trigger(self, trigger: Option<&'i str>) -> Option<&'i str> { |
77 | | - self.into() |
78 | | - .filter(|e| none_empty(e.rsplit('?')) == trigger) |
79 | | - .and_then(|e| none_empty(e.split('?'))) |
80 | | - } |
81 | | - fn triggers_with_same_guard(self, guard: Option<&'i str>) -> Option<&'i str> { |
82 | | - self.into() |
83 | | - .filter(|e| none_empty(e.split('?')) == guard) |
84 | | - .and_then(|e| none_empty(e.rsplit('?'))) |
85 | | - } |
86 | | - fn as_expression(self) -> String { |
87 | | - self.into().map(String::as_str).as_expression() |
88 | | - } |
89 | | -} |
90 | | - |
91 | | -impl<'o> Trigger<'o> for &'o Option<&'o str> {} |
92 | | -trait Trigger<'o>: Into<Option<&'o &'o str>> { |
93 | | - fn as_expression(self) -> String { |
94 | | - self.into() |
95 | | - .map(|s| { |
96 | | - format!( |
97 | | - " @ {trigger}{guard}", |
98 | | - trigger = none_empty(s.rsplit('?')).unwrap_or_default(), |
99 | | - guard = none_empty(s.split('?')) |
100 | | - .filter(|_| s.contains('?')) |
101 | | - .map(|g| format!("[{}]", g)) |
102 | | - .unwrap_or_default(), |
103 | | - ) |
104 | | - }) |
105 | | - .unwrap_or_default() |
106 | | - } |
107 | | - fn as_key(self, guard: &str) -> Option<String> { |
108 | | - Some(format!("{}?{}", self.into().unwrap_or(&""), guard)) |
109 | | - } |
110 | | -} |
111 | | - |
112 | 55 | impl<'t> SemanticAnalyze<'t> for Transition<'t> { |
113 | 56 | fn analyze_error(&self, span: Span<'t>, options: &'t Scdlang) -> Result<(), Error> { |
114 | 57 | let make_error = |message| options.err_from_span(span, message).into(); |
@@ -139,17 +82,9 @@ impl<'t> SemanticAnalyze<'t> for Transition<'t> { |
139 | 82 | } |
140 | 83 | } |
141 | 84 |
|
142 | | -fn is_empty<'a>(split: impl Iterator<Item = &'a str>) -> bool { |
143 | | - none_empty(split).is_some() |
144 | | -} |
145 | | - |
146 | | -fn none_empty<'a>(split: impl Iterator<Item = &'a str>) -> Option<&'a str> { |
147 | | - split.last().filter(|s| !s.is_empty()) |
148 | | -} |
149 | | - |
150 | 85 | use std::collections::HashMap; |
151 | 86 | type CacheMap = HashMap<Option<String>, String>; |
152 | | -type CachedTransition<'state> = MutexGuard<'state, cache::MapTransition>; |
| 87 | +type CachedTransition<'state> = MutexGuard<'state, cache::TransitionMap>; |
153 | 88 |
|
154 | 89 | impl<'t> Transition<'t> { |
155 | 90 | fn cache_current_state<'a>(&self, cache: &'t mut CachedTransition<'a>) -> &'t mut CacheMap { |
|
0 commit comments