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
73
74
75
76
77
78
use crate::data::ast::Interval;
use crate::data::position::Position;
use lazy_static::*;
use std::collections::*;
use std::sync::*;
use std::thread::*;
pub const WARNING_USE: & str = "use will be soon a deprecated keyword please use 'do' instead. https://docs.csml.dev/memory/temporary-and-long-term-variables";
pub const WARNING_REMEMBER_AS: & str = "'remember value as key' will be soon a deprecated keyword please use 'remember key = value' instead. https://docs.csml.dev/memory/temporary-and-long-term-variables";
pub const WARNING_OBJECT: & str = "'Object(key = value)' will be soon a deprecated Macro please use '{key: value}' instead; https://docs.csml.dev/automatic-type-inference/literals-objects-arrays";
lazy_static! {
static ref HASHMAP: Mutex<HashMap<ThreadId, Vec<Warnings>>> = Mutex::new(HashMap::default());
}
#[derive(Debug, Clone)]
pub struct Warnings {
pub message: &'static str,
pub position: Position,
}
impl Warnings {
fn new(interval: Interval, message: &'static str) -> Self {
Self {
message,
position: Position::new(interval),
}
}
}
impl Warnings {
pub fn add(message: &'static str, interval: Interval) {
let thread_id = current().id();
let mut hashmap = HASHMAP.lock().unwrap();
hashmap.entry(thread_id).or_insert_with(Vec::default);
if let Some(vector) = hashmap.get_mut(&thread_id) {
vector.push(Warnings::new(interval, message));
}
}
pub fn clear() {
let thread_id = current().id();
let mut hashmap = HASHMAP.lock().unwrap();
hashmap.entry(thread_id).or_insert_with(Vec::default);
if let Some(vector) = hashmap.get_mut(&thread_id) {
vector.clear();
}
}
pub fn get() -> Vec<Warnings> {
let thread_id = current().id();
let mut hashmap = HASHMAP.lock().unwrap();
hashmap.entry(thread_id).or_insert_with(Vec::default);
if let Some(vector) = hashmap.get(&thread_id) {
vector.to_owned()
} else {
unreachable!();
}
}
}