aboutsummaryrefslogtreecommitdiffstats
path: root/modelica-parser-lalrpop/src/ast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'modelica-parser-lalrpop/src/ast.rs')
-rw-r--r--modelica-parser-lalrpop/src/ast.rs70
1 files changed, 35 insertions, 35 deletions
diff --git a/modelica-parser-lalrpop/src/ast.rs b/modelica-parser-lalrpop/src/ast.rs
index e367b10..52e91b8 100644
--- a/modelica-parser-lalrpop/src/ast.rs
+++ b/modelica-parser-lalrpop/src/ast.rs
@@ -9,7 +9,7 @@ use std::collections::HashMap;
pub enum ModelicaCode {
Class, // unimpl; generic
Model(ModelicaModel),
- Record, // unimpl
+ Record(ModelicaRecord),
Block(ModelicaBlock),
Connector(ModelicaConnector),
Type(ModelicaType),
@@ -38,29 +38,34 @@ pub struct ModelicaType {
pub struct ModelicaBlock {
pub name: String,
pub description: Option<String>,
- pub component_clauses: Vec<ComponentClause>,
- pub public_component_clauses: Vec<ComponentClause>,
- pub protected_component_clauses: Vec<ComponentClause>,
+ pub components: Vec<Component>,
+ pub public_components: Vec<Component>,
+ pub protected_components: Vec<Component>,
pub equations: Vec<SimpleEquation>,
pub connections: Vec<Connection>,
- pub extends: Vec<String>,
}
#[derive(Clone, PartialEq)]
pub struct ModelicaConnector {
pub name: String,
pub description: Option<String>,
- pub component_clauses: Vec<ComponentClause>,
+ pub components: Vec<Component>,
+}
+
+#[derive(Clone, PartialEq)]
+pub struct ModelicaRecord {
+ pub name: String,
+ pub description: Option<String>,
+ pub components: Vec<Component>,
}
#[derive(Clone, PartialEq)]
pub struct ModelicaModel {
pub name: String,
pub description: Option<String>,
- pub component_clauses: Vec<ComponentClause>,
+ pub components: Vec<Component>,
pub equations: Vec<SimpleEquation>,
pub connections: Vec<Connection>,
- pub extends: Vec<String>,
}
#[derive(Copy, Clone, PartialEq)]
@@ -158,32 +163,31 @@ pub enum BinOperator {
//// Helpers
-impl ModelicaModel {
-
- // This flattens the ComponentClause/ComponentDeclaration tree into a flat
- // list of Components
- // TODO: refactor this into an iterator `components()`?
- pub fn get_components(&self) -> Vec<Component> {
-
- let mut vars: Vec<Component> = vec![];
- for clause in &self.component_clauses {
- vars.extend(clause.declarations.iter().map(|ref dec|
- Component {
- prefix: clause.prefix.clone(),
- specifier: clause.specifier.clone(),
- name: dec.name.clone(),
- value: dec.value.clone(),
- mods: dec.mods.clone(),
- description: dec.description.clone(),
- }))
- }
- vars
+// This flattens the ComponentClause/ComponentDeclaration tree into a flat
+// list of Components
+pub fn collapse_components(clauses: &Vec<ComponentClause>) -> Vec<Component> {
+
+ let mut vars: Vec<Component> = vec![];
+ for clause in clauses {
+ vars.extend(clause.declarations.iter().map(|ref dec|
+ Component {
+ prefix: clause.prefix.clone(),
+ specifier: clause.specifier.clone(),
+ name: dec.name.clone(),
+ value: dec.value.clone(),
+ mods: dec.mods.clone(),
+ description: dec.description.clone(),
+ }))
}
+ vars
+}
+
+impl ModelicaModel {
pub fn get_constant_vars(&self) -> HashMap<String,Option<Expr>> {
let mut binds = HashMap::new();
// XXX: actually implement this...
- for c in &self.get_components() {
+ for c in &self.components {
match c.prefix {
Some(ComponentPrefix::Constant) => { binds.insert(c.name.clone(), Some(Expr::Integer(123))); },
Some(ComponentPrefix::Parameter) => { binds.insert(c.name.clone(), Some(Expr::Float(4.56))); },
@@ -199,8 +203,7 @@ impl ModelicaModel {
// if a var is on LHS and RHS of same equation
pub fn get_free_vars(&self) -> Vec<String> {
// Start with components, and remove constants and parameters
- let components = self.get_components();
- let vars = components.iter().filter(|v| match v.prefix {
+ let vars = self.components.iter().filter(|v| match v.prefix {
Some(ComponentPrefix::Constant) | Some(ComponentPrefix::Parameter) => false,
_ => true,
});
@@ -278,10 +281,7 @@ impl SimpleEquation {
impl Debug for ModelicaModel {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
try!(write!(fmt, "model {}\n", self.name));
- for e in self.extends.iter() {
- try!(write!(fmt, " extends {};\n", e));
- }
- for v in self.get_components().iter() {
+ for v in self.components.iter() {
try!(write!(fmt, " {:?};\n", v));
}
try!(write!(fmt, "equation\n"));