From cc971bc1e379d9ad84e488b0ba99cca1653b4d6d Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sat, 24 Sep 2022 17:40:18 +0800 Subject: [PATCH] feat(fkl): try t oadd to aggregate --- crates/fkl_parser/src/transform.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/fkl_parser/src/transform.rs b/crates/fkl_parser/src/transform.rs index ee3bd91..3ecd13b 100644 --- a/crates/fkl_parser/src/transform.rs +++ b/crates/fkl_parser/src/transform.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use indexmap::IndexMap; use crate::{ContextMap, mir, ParseError}; @@ -9,6 +10,7 @@ use crate::parser::parse as ast_parse; pub struct MirTransform { pub context_map_name: String, pub contexts: IndexMap, + // pub contexts: HashMap, pub aggregates: IndexMap, pub relations: Vec, } @@ -29,6 +31,8 @@ impl MirTransform { Err(e) => return Err(e), }; + transform.build_context_map(); + Ok(ContextMap { name: transform.context_map_name, state: Default::default(), @@ -37,6 +41,24 @@ impl MirTransform { }) } + fn build_context_map(&self) -> Vec { + let mut contexts = vec![]; + + self.contexts.values().for_each(|context| { + let mut context = BoundedContext::new(&context.name); + + for aggregate in context.aggregates.clone() { + if let Some(agg) = self.aggregates.get(&aggregate.name) { + context.aggregates.push(agg.clone()); + } else { + context.aggregates.push(aggregate.clone()) + } + } + }); + + contexts + } + fn lower_decls(&mut self, decls: Vec) { decls.iter().for_each(|declaration| { match declaration {