1
+ use std:: { collections:: HashMap , rc:: Rc } ;
2
+
3
+ use plc_source:: source_location:: SourceLocation ;
4
+
5
+ use crate :: typesystem:: DataType ;
6
+
7
+ use super :: VariableIndexEntry ;
8
+
9
+ /// A minimal index implementation that can be used for local scopes
10
+ #[ derive( Debug , Clone ) ]
11
+ pub struct ScopedIndex {
12
+ ///The scope of the current index, this is usually a POU
13
+ scope : String ,
14
+
15
+ /// A unique identifier that new variables in this scope will inherit
16
+ scope_suffix : usize ,
17
+
18
+ /// The location that caused this scope to be created
19
+ start_location : SourceLocation ,
20
+
21
+ /// New variables defined by this index
22
+ variables : HashMap < String , VariableIndexEntry > ,
23
+
24
+ /// Datatypes defined by this index
25
+ type_index : HashMap < String , DataType > ,
26
+
27
+ parent : Option < Rc < ScopedIndex > >
28
+
29
+ }
30
+
31
+ impl ScopedIndex {
32
+ pub fn merge_into ( self , target : & mut Self ) {
33
+ target. variables . extend ( self . variables ) ;
34
+ target. type_index . extend ( self . type_index ) ;
35
+ }
36
+
37
+ pub fn add_variable ( & mut self , name : & str ) {
38
+
39
+ }
40
+
41
+ pub fn add_type ( & mut self , name : & str ) {
42
+
43
+ }
44
+
45
+ pub fn find_variable ( & self , name : & str ) -> Option < & VariableIndexEntry > {
46
+ todo ! ( )
47
+ }
48
+
49
+ pub fn find_type ( & self , name : & str ) -> Option < & DataType > {
50
+ todo ! ( )
51
+ }
52
+
53
+ pub fn new ( parent : Option < Rc < ScopedIndex > > , location : SourceLocation , scope : & str , suffix : usize ) -> ScopedIndex {
54
+ ScopedIndex { scope : scope. to_string ( ) , scope_suffix : suffix, start_location : location, parent, type_index : Default :: default ( ) , variables : Default :: default ( ) }
55
+ }
56
+
57
+ }
0 commit comments