@@ -402,24 +402,25 @@ pub fn compile_module<'c, T: SourceContainer>(
402
402
403
403
// ### PHASE 1 ###
404
404
// parse & index everything
405
- parse_and_index (
405
+ let ( index , mut units ) = parse_and_index (
406
406
sources,
407
407
encoding,
408
408
& id_provider,
409
409
& mut diagnostician,
410
- & mut full_index,
411
- & mut all_units,
412
410
LinkageType :: Internal ,
413
411
) ?;
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 (
415
416
includes,
416
417
encoding,
417
418
& id_provider,
418
419
& mut diagnostician,
419
- & mut full_index,
420
- & mut all_units,
421
420
LinkageType :: External ,
422
421
) ?;
422
+ full_index. import ( includes_index) ;
423
+ all_units. append ( & mut includes_units) ;
423
424
424
425
// ### PHASE 1.1 resolve constant literal values
425
426
let ( mut full_index, _unresolvables) =
@@ -458,15 +459,17 @@ pub fn compile_module<'c, T: SourceContainer>(
458
459
Ok ( code_generator)
459
460
}
460
461
462
+ type Units = Vec < ( usize , Vec < Diagnostic > , CompilationUnit ) > ;
461
463
fn parse_and_index < T : SourceContainer > (
462
464
source : Vec < T > ,
463
465
encoding : Option < & ' static Encoding > ,
464
466
id_provider : & IdProvider ,
465
467
diagnostician : & mut Diagnostician ,
466
- full_index : & mut Index ,
467
- all_units : & mut Vec < ( usize , Vec < Diagnostic > , CompilationUnit ) > ,
468
468
linkage : LinkageType ,
469
- ) -> Result < ( ) , Diagnostic > {
469
+ ) -> Result < ( Index , Units ) , Diagnostic > {
470
+ let mut index = Index :: new ( ) ;
471
+ let mut units = Vec :: new ( ) ;
472
+
470
473
for container in source {
471
474
let location: String = container. get_location ( ) . into ( ) ;
472
475
let e = container
@@ -481,13 +484,13 @@ fn parse_and_index<T: SourceContainer>(
481
484
//pre-process the ast (create inlined types)
482
485
ast:: pre_process ( & mut parse_result, id_provider. clone ( ) ) ;
483
486
//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 ( ) ) ) ;
485
488
486
489
//register the file with the diagnstician, so diagnostics are later able to show snippets from the code
487
490
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) ) ;
489
492
}
490
- Ok ( ( ) )
493
+ Ok ( ( index , units ) )
491
494
}
492
495
493
496
fn create_file_paths ( inputs : & [ String ] ) -> Result < Vec < FilePath > , Diagnostic > {
0 commit comments