1
0

Rename and clean up

This commit is contained in:
Jeff 2024-03-14 11:49:10 -04:00
parent fdf286cb51
commit 5b79af6e85
3 changed files with 10 additions and 10 deletions

View File

@ -70,7 +70,7 @@ impl AbstractTree for Assignment {
context.set_value(self.identifier, value)?; context.set_value(self.identifier, value)?;
} }
AssignmentOperator::AddAssign => { AssignmentOperator::AddAssign => {
if let Some(previous_value) = context.get_value(&self.identifier)? { if let Some(previous_value) = context.use_value(&self.identifier)? {
let new_value = previous_value.add(&value)?; let new_value = previous_value.add(&value)?;
context.set_value(self.identifier, new_value)?; context.set_value(self.identifier, new_value)?;
@ -81,7 +81,7 @@ impl AbstractTree for Assignment {
} }
} }
AssignmentOperator::SubAssign => { AssignmentOperator::SubAssign => {
if let Some(previous_value) = context.get_value(&self.identifier)? { if let Some(previous_value) = context.use_value(&self.identifier)? {
let new_value = previous_value.subtract(&value)?; let new_value = previous_value.subtract(&value)?;
context.set_value(self.identifier, new_value)?; context.set_value(self.identifier, new_value)?;
@ -121,7 +121,7 @@ mod tests {
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
context.get_value(&Identifier::new("foobar")), context.use_value(&Identifier::new("foobar")),
Ok(Some(Value::integer(42))) Ok(Some(Value::integer(42)))
) )
} }
@ -144,7 +144,7 @@ mod tests {
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
context.get_value(&Identifier::new("foobar")), context.use_value(&Identifier::new("foobar")),
Ok(Some(Value::integer(42))) Ok(Some(Value::integer(42)))
) )
} }
@ -167,7 +167,7 @@ mod tests {
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
context.get_value(&Identifier::new("foobar")), context.use_value(&Identifier::new("foobar")),
Ok(Some(Value::integer(42))) Ok(Some(Value::integer(42)))
) )
} }

View File

@ -25,7 +25,7 @@ impl Identifier {
impl AbstractTree for Identifier { impl AbstractTree for Identifier {
fn expected_type(&self, context: &Context) -> Result<Type, ValidationError> { fn expected_type(&self, context: &Context) -> Result<Type, ValidationError> {
if let Some(r#type) = context.get_type(self)? { if let Some(r#type) = context.use_type(self)? {
Ok(r#type) Ok(r#type)
} else { } else {
Err(ValidationError::VariableNotFound(self.clone())) Err(ValidationError::VariableNotFound(self.clone()))
@ -41,7 +41,7 @@ impl AbstractTree for Identifier {
} }
fn run(self, context: &Context) -> Result<Action, RuntimeError> { fn run(self, context: &Context) -> Result<Action, RuntimeError> {
let return_action = context.get_value(&self)?.map(|value| Action::Return(value)); let return_action = context.use_value(&self)?.map(|value| Action::Return(value));
if let Some(action) = return_action { if let Some(action) = return_action {
Ok(action) Ok(action)

View File

@ -94,7 +94,7 @@ impl Context {
} }
} }
pub fn get_data( pub fn use_data(
&self, &self,
identifier: &Identifier, identifier: &Identifier,
) -> Result<Option<ValueData>, RwLockPoisonError> { ) -> Result<Option<ValueData>, RwLockPoisonError> {
@ -129,7 +129,7 @@ impl Context {
Ok(Some(value_data)) Ok(Some(value_data))
} }
pub fn get_type(&self, identifier: &Identifier) -> Result<Option<Type>, RwLockPoisonError> { pub fn use_type(&self, identifier: &Identifier) -> Result<Option<Type>, RwLockPoisonError> {
if let Some((ValueData::Type(r#type), usage_data)) = self.inner.read()?.get(identifier) { if let Some((ValueData::Type(r#type), usage_data)) = self.inner.read()?.get(identifier) {
log::trace!("Adding use for variable: {identifier}"); log::trace!("Adding use for variable: {identifier}");
@ -146,7 +146,7 @@ impl Context {
Ok(Some(r#type)) Ok(Some(r#type))
} }
pub fn get_value(&self, identifier: &Identifier) -> Result<Option<Value>, RwLockPoisonError> { pub fn use_value(&self, identifier: &Identifier) -> Result<Option<Value>, RwLockPoisonError> {
let should_remove = if let Some((ValueData::Value(value), usage_data)) = let should_remove = if let Some((ValueData::Value(value), usage_data)) =
self.inner.read()?.get(identifier) self.inner.read()?.get(identifier)
{ {