Skip to content

Commit 4217a72

Browse files
committed
review changes, cli info text, parse_and_index() return index and units
1 parent 0e23a42 commit 4217a72

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/cli.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub struct CompileParameters {
108108
name = "include",
109109
long,
110110
short = "i",
111-
help = "Include .st files for external functions"
111+
help = "Include source files for external functions"
112112
)]
113113
pub includes: Vec<String>,
114114
}

src/lib.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -402,24 +402,25 @@ pub fn compile_module<'c, T: SourceContainer>(
402402

403403
// ### PHASE 1 ###
404404
// parse & index everything
405-
parse_and_index(
405+
let (index, mut units) = parse_and_index(
406406
sources,
407407
encoding,
408408
&id_provider,
409409
&mut diagnostician,
410-
&mut full_index,
411-
&mut all_units,
412410
LinkageType::Internal,
413411
)?;
414-
parse_and_index(
412+
full_index.import(index);
413+
all_units.append(&mut units);
414+
415+
let (includes_index, mut includes_units) = parse_and_index(
415416
includes,
416417
encoding,
417418
&id_provider,
418419
&mut diagnostician,
419-
&mut full_index,
420-
&mut all_units,
421420
LinkageType::External,
422421
)?;
422+
full_index.import(includes_index);
423+
all_units.append(&mut includes_units);
423424

424425
// ### PHASE 1.1 resolve constant literal values
425426
let (mut full_index, _unresolvables) =
@@ -458,15 +459,17 @@ pub fn compile_module<'c, T: SourceContainer>(
458459
Ok(code_generator)
459460
}
460461

462+
type Units = Vec<(usize, Vec<Diagnostic>, CompilationUnit)>;
461463
fn parse_and_index<T: SourceContainer>(
462464
source: Vec<T>,
463465
encoding: Option<&'static Encoding>,
464466
id_provider: &IdProvider,
465467
diagnostician: &mut Diagnostician,
466-
full_index: &mut Index,
467-
all_units: &mut Vec<(usize, Vec<Diagnostic>, CompilationUnit)>,
468468
linkage: LinkageType,
469-
) -> Result<(), Diagnostic> {
469+
) -> Result<(Index, Units), Diagnostic> {
470+
let mut index = Index::new();
471+
let mut units = Vec::new();
472+
470473
for container in source {
471474
let location: String = container.get_location().into();
472475
let e = container
@@ -481,13 +484,13 @@ fn parse_and_index<T: SourceContainer>(
481484
//pre-process the ast (create inlined types)
482485
ast::pre_process(&mut parse_result, id_provider.clone());
483486
//index the pou
484-
full_index.import(index::visitor::visit(&parse_result, id_provider.clone()));
487+
index.import(index::visitor::visit(&parse_result, id_provider.clone()));
485488

486489
//register the file with the diagnstician, so diagnostics are later able to show snippets from the code
487490
let file_id = diagnostician.register_file(location.clone(), e.source);
488-
all_units.push((file_id, diagnostics, parse_result));
491+
units.push((file_id, diagnostics, parse_result));
489492
}
490-
Ok(())
493+
Ok((index, units))
491494
}
492495

493496
fn create_file_paths(inputs: &[String]) -> Result<Vec<FilePath>, Diagnostic> {

0 commit comments

Comments
 (0)