Skip to content

Commit

Permalink
Fixed submodules of included files not getting exported
Browse files Browse the repository at this point in the history
  • Loading branch information
mschae23 committed Aug 5, 2022
1 parent 067a77c commit fabc2d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "density_function_lang"
version = "3.1.0"
version = "3.1.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
41 changes: 16 additions & 25 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ impl Compiler {
}

fn collect_exports_impl(outputs: &mut Vec<Rc<RefCell<ExportFunction>>>, module: Rc<RefCell<Module>>, target_dir: &Path) {
outputs.extend(module.borrow().exports.iter().map(|export| {
outputs.extend(module.borrow().exports.iter()
.map(|export| {
let export_borrow = export.borrow();
let mut target_path = target_dir.to_owned();
target_path.push(&export_borrow.name);
Expand All @@ -84,11 +85,12 @@ impl Compiler {

let mut path = target_dir.to_owned();

for sub_module in &module_borrow.sub_modules {
for sub_module in module_borrow.sub_modules.iter().chain(module_borrow.imported_sub_modules.iter()) {
path.push(&sub_module.borrow().name);
Self::collect_exports_impl(outputs, Rc::clone(sub_module), &path);
path.pop();
}

}

fn compile_declaration(&mut self, decl: Decl) {
Expand Down Expand Up @@ -173,11 +175,8 @@ impl Compiler {
}

let module = self.current_module.pop().expect("Internal compiler error: Missing module");
let mut module_borrow = module.borrow_mut();
module_borrow.imported_sub_modules.clear();
module_borrow.imported_templates.clear();
module_borrow.imported_exports.clear();
drop(module_borrow);
// let mut module_borrow = module.borrow_mut();
// drop(module_borrow);

if !extending {
self.current_module().borrow_mut().sub_modules.push(module);
Expand Down Expand Up @@ -234,7 +233,7 @@ impl Compiler {
&self.current_module[module_index as usize]
} else { &self.top_level_module });

match Self::find_submodule(&module, &path[0]) {
match Self::find_submodule(&module, &path[0], true) {
Some(sub_module) => {
module = sub_module;
break;
Expand All @@ -251,7 +250,7 @@ impl Compiler {
}

for name in path.iter().skip(1) {
match Self::find_submodule(&module, name) {
match Self::find_submodule(&module, name, false) {
Some(sub_module) => {
module = sub_module;
},
Expand All @@ -265,7 +264,7 @@ impl Compiler {
let current_module = self.current_module();
let mut current_module_borrow = current_module.borrow_mut();

for template in module.borrow().templates.iter().chain(module.borrow().imported_templates.iter()) {
for template in module.borrow().templates.iter() {
let template_name = &template.borrow().name;
let template_arg_count = template.borrow().args.len();
let mut allow = true;
Expand All @@ -291,7 +290,7 @@ impl Compiler {
}
}

for sub_module in module.borrow().sub_modules.iter().chain(module.borrow().imported_sub_modules.iter()) {
for sub_module in module.borrow().sub_modules.iter() {
let sub_module_name = &sub_module.borrow().name;
let mut allow = true;

Expand All @@ -317,8 +316,12 @@ impl Compiler {
}
}

fn find_submodule(module: &Rc<RefCell<Module>>, name: &Token) -> Option<Rc<RefCell<Module>>> {
for sub_module in module.borrow().sub_modules.iter().chain(module.borrow().imported_sub_modules.iter()) {
fn find_submodule(module: &Rc<RefCell<Module>>, name: &Token, include_imported: bool) -> Option<Rc<RefCell<Module>>> {
let empty = [];
let module_borrow = module.borrow();

for sub_module in module_borrow.sub_modules.iter().chain(
if include_imported { module_borrow.imported_sub_modules.iter() } else { empty.iter() }) {
if sub_module.borrow().name == *name.source() {
return Some(Rc::clone(sub_module));
}
Expand Down Expand Up @@ -717,24 +720,12 @@ impl Compiler {
}
}

for template in &module.borrow().imported_templates {
if *template.borrow().name == *name.source() {
return JsonElement::Template(Rc::clone(template));
}
}

for sub_module in &module.borrow().sub_modules {
if *sub_module.borrow().name == *name.source() {
return JsonElement::Module(Rc::clone(sub_module));
}
}

for sub_module in &module.borrow().imported_sub_modules {
if *sub_module.borrow().name == *name.source() {
return JsonElement::Module(Rc::clone(sub_module));
}
}

self.error_at(*name.start(), &format!("Unresolved reference: '{}'", name.source()), false);
JsonElement::Error
},
Expand Down

0 comments on commit fabc2d8

Please sign in to comment.