-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The scoped index contains new variables and datatypes that could later be merged into the main index. Any ast statetment that could declare new variables or represents a scope is marked with a new scope. Further statements would inherit this scope to see new variables. TODO: Going out of scope would merge the new variables with unique names back into the index. Co-authored-by: Michael <[email protected]>
- Loading branch information
Showing
6 changed files
with
302 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use std::{collections::HashMap, rc::Rc}; | ||
|
||
use plc_ast::provider::IdProvider; | ||
use plc_source::source_location::SourceLocation; | ||
|
||
use crate::typesystem::DataType; | ||
|
||
use super::VariableIndexEntry; | ||
|
||
/// A minimal index implementation that can be used for local scopes | ||
#[derive(Debug, Clone)] | ||
pub struct ScopedIndex { | ||
///The scope of the current index, this is usually a POU | ||
scope: String, | ||
|
||
/// A unique identifier that new variables in this scope will inherit | ||
suffix_provider: IdProvider, | ||
|
||
/// The location that caused this scope to be created | ||
start_location: SourceLocation, | ||
|
||
/// New variables defined by this index | ||
variables: HashMap<String, VariableIndexEntry>, | ||
|
||
/// Datatypes defined by this index | ||
type_index: HashMap<String, DataType>, | ||
|
||
parent: Option<Rc<ScopedIndex>>, | ||
} | ||
|
||
impl ScopedIndex { | ||
pub fn merge_into(self, target: &mut Self) { | ||
target.variables.extend(self.variables); | ||
target.type_index.extend(self.type_index); | ||
} | ||
|
||
pub fn add_variable(&mut self, _name: &str) {} | ||
|
||
pub fn add_type(&mut self, _name: &str) {} | ||
|
||
pub fn find_variable(&self, _name: &str) -> Option<&VariableIndexEntry> { | ||
todo!() | ||
} | ||
|
||
pub fn find_type(&self, _name: &str) -> Option<&DataType> { | ||
todo!() | ||
} | ||
|
||
pub fn new( | ||
parent: Option<Rc<ScopedIndex>>, | ||
location: SourceLocation, | ||
scope: &str, | ||
suffix_provider: IdProvider, | ||
) -> ScopedIndex { | ||
ScopedIndex { | ||
scope: scope.to_string(), | ||
suffix_provider, | ||
start_location: location, | ||
parent, | ||
type_index: Default::default(), | ||
variables: Default::default(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.