use crate::gml::Instruction;
use crate::gml::instruction::DataType;
use crate::prelude::*;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct CodeAnalysis {
pub array_cow: bool,
pub short_circuit: bool,
}
impl Default for CodeAnalysis {
fn default() -> Self {
Self { array_cow: false, short_circuit: true }
}
}
#[must_use]
pub fn analyze(data: &GMData) -> CodeAnalysis {
let mut analysis = CodeAnalysis::default();
for code in data.codes.elements() {
for instruction in &code.instructions {
match instruction {
Instruction::And { lhs: DataType::Bool, rhs: DataType::Bool }
| Instruction::Or { lhs: DataType::Bool, rhs: DataType::Bool } => {
analysis.short_circuit = false;
}
Instruction::SetArrayOwner => {
analysis.array_cow = true;
}
_ => {}
}
}
}
analysis
}