Skip to content

Commit

Permalink
Merge pull request #305 from Sacul231/master
Browse files Browse the repository at this point in the history
Minor: improving known/unknown tags
  • Loading branch information
clararod9 authored Oct 7, 2024
2 parents 89e2443 + 16a07c6 commit 104d984
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
34 changes: 33 additions & 1 deletion constraint_generation/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2806,8 +2806,40 @@ fn execute_bus(
}

Result::Ok(FoldedValue{bus_slice: Some((symbol.to_string(), bus_slice)), tags: Some(tags_propagated), ..FoldedValue::default()})
} else if tags.contains_key(access_information.field_access.as_ref().unwrap()){
// case tags
let acc = access_information.field_access.unwrap();
let value_tag = tags.get(&acc).unwrap();
let state = tags_definitions.get(&acc).unwrap();
if let Some(value_tag) = value_tag { // tag has value
// access only allowed when (1) it is value defined by user or (2) it is completely assigned
if state.value_defined || state.complete{
let a_value = AExpr::Number { value: value_tag.clone() };
let ae_slice = AExpressionSlice::new(&a_value);
Result::Ok(FoldedValue { arithmetic_slice: Option::Some(ae_slice), ..FoldedValue::default() })
} else{
let error = MemoryError::TagValueNotInitializedAccess;
treat_result_with_memory_error(
Result::Err(error),
meta,
&mut runtime.runtime_errors,
&runtime.call_trace,
)?
}

}
else {
let error = MemoryError::TagValueNotInitializedAccess;
treat_result_with_memory_error(
Result::Err(error),
meta,
&mut runtime.runtime_errors,
&runtime.call_trace,
)?
}

} else{
// access to the field or tag
// access to the field or tag of a field

let resulting_bus = safe_unwrap_to_single(bus_slice, line!());
let symbol = create_symbol_bus(symbol, &access_information);
Expand Down
21 changes: 2 additions & 19 deletions type_analysis/src/analyzers/unknown_known_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ fn tag(expression: &Expression, environment: &Environment) -> Tag {
use Tag::*;
match expression {
Number(_, _) => Known,
Variable { meta, name, access,.. } => {
Variable { meta, name,.. } => {
let reduced_type = meta.get_type_knowledge().get_reduces_to();
let mut symbol_tag = match reduced_type {
match reduced_type {
TypeReduction::Variable => {
let (tag, is_array) = environment.get_variable_or_break(name, file!(), line!());
if *is_array{
Expand All @@ -414,23 +414,6 @@ fn tag(expression: &Expression, environment: &Environment) -> Tag {
TypeReduction::Bus(_) => Unknown,
TypeReduction::Component(_) => *environment.get_component_or_break(name, file!(), line!()),
TypeReduction::Tag => Known,
};


let mut index = 0;
loop {
if index == access.len() {
break symbol_tag;
}
if symbol_tag == Unknown {
break Unknown;
}
if let Access::ArrayAccess(exp) = &access[index] {
symbol_tag = tag(exp, environment);
} else if !environment.has_intermediate(name) {
symbol_tag = Unknown;
}
index += 1;
}
}
ArrayInLine { values, .. }
Expand Down

0 comments on commit 104d984

Please sign in to comment.