aboutsummaryrefslogtreecommitdiffstats
path: root/src/modelica_ast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/modelica_ast.rs')
-rw-r--r--src/modelica_ast.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/modelica_ast.rs b/src/modelica_ast.rs
index 68eafaf..9e25b1b 100644
--- a/src/modelica_ast.rs
+++ b/src/modelica_ast.rs
@@ -1,5 +1,6 @@
use std::fmt::{Debug, Formatter, Error};
+use std::collections::HashMap;
#[derive(PartialEq)]
pub struct ModelicaModel {
@@ -59,6 +60,43 @@ pub enum BinOperator {
Subtract,
}
+//// Helpers
+
+impl ModelicaModel {
+
+ pub fn get_constant_vars(&self) -> HashMap<String,Expr> {
+ let mut binds = HashMap::new();
+ for c in &self.components {
+ match c.prefix {
+ Some(ComponentPrefix::Constant) => { binds.insert(c.name.clone(), Expr::Integer(123)); },
+ Some(ComponentPrefix::Parameter) => { binds.insert(c.name.clone(), Expr::Float(4.56)); },
+ _ => (),
+ }
+ }
+ binds
+ }
+
+ pub fn get_free_vars(&self) -> Vec<String> {
+ // Start with components, and remove constants and parameters
+ let vars = self.components.iter().filter(|v| match v.prefix {
+ Some(ComponentPrefix::Constant) | Some(ComponentPrefix::Parameter) => false,
+ _ => true,
+ });
+
+ // Remove LHS (bound) vars
+ let mut outputs = vec![];
+ for eq in self.equations.iter() {
+ // TODO:
+ if let Expr::Ident(ref symb) = eq.lhs {
+ outputs.push(symb.to_string());
+ }
+ }
+ let vars = vars.filter(|v| !outputs.contains(&v.name));
+
+ vars.map(|c| c.name.clone()).collect()
+ }
+}
+
//// Debug Implementations
impl Debug for ModelicaModel {