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)?;
}
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)?;
context.set_value(self.identifier, new_value)?;
@ -81,7 +81,7 @@ impl AbstractTree for Assignment {
}
}
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)?;
context.set_value(self.identifier, new_value)?;
@ -121,7 +121,7 @@ mod tests {
.unwrap();
assert_eq!(
context.get_value(&Identifier::new("foobar")),
context.use_value(&Identifier::new("foobar")),
Ok(Some(Value::integer(42)))
)
}
@ -144,7 +144,7 @@ mod tests {
.unwrap();
assert_eq!(
context.get_value(&Identifier::new("foobar")),
context.use_value(&Identifier::new("foobar")),
Ok(Some(Value::integer(42)))
)
}
@ -167,7 +167,7 @@ mod tests {
.unwrap();
assert_eq!(
context.get_value(&Identifier::new("foobar")),
context.use_value(&Identifier::new("foobar")),
Ok(Some(Value::integer(42)))
)
}

View File

@ -25,7 +25,7 @@ impl Identifier {
impl AbstractTree for Identifier {
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)
} else {
Err(ValidationError::VariableNotFound(self.clone()))
@ -41,7 +41,7 @@ impl AbstractTree for Identifier {
}
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 {
Ok(action)

View File

@ -94,7 +94,7 @@ impl Context {
}
}
pub fn get_data(
pub fn use_data(
&self,
identifier: &Identifier,
) -> Result<Option<ValueData>, RwLockPoisonError> {
@ -129,7 +129,7 @@ impl Context {
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) {
log::trace!("Adding use for variable: {identifier}");
@ -146,7 +146,7 @@ impl Context {
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)) =
self.inner.read()?.get(identifier)
{