@@ -8,9 +8,11 @@ use std::{
8
8
9
9
use clang:: {
10
10
Clang ,
11
+ diagnostic:: Severity ,
11
12
Entity ,
12
13
EntityKind ,
13
14
Index ,
15
+ TranslationUnit ,
14
16
Type ,
15
17
} ;
16
18
use dunce:: canonicalize;
@@ -361,22 +363,36 @@ impl Generator {
361
363
args
362
364
}
363
365
364
- pub fn process_module ( & self , module : & str , entity_processor : impl FnOnce ( Entity ) ) {
366
+ pub fn process_module ( & self , module : & str , panic_on_error : bool , entity_processor : impl FnOnce ( Entity ) ) {
365
367
let index = Index :: new ( & self . clang , true , false ) ;
366
368
let mut module_file = self . src_cpp_dir . join ( format ! ( "{}.hpp" , module) ) ;
367
369
if !module_file. exists ( ) {
368
370
module_file = self . opencv_include_dir . join ( format ! ( "opencv2/{}.hpp" , module) ) ;
369
371
}
370
- let root_tu = index. parser ( module_file)
372
+ let root_tu: TranslationUnit = index. parser ( module_file)
371
373
. arguments ( & self . build_clang_command_line_args ( ) )
372
374
. detailed_preprocessing_record ( true )
373
375
. skip_function_bodies ( true )
374
376
. parse ( ) . expect ( "Cannot parse" ) ;
377
+ let diags = root_tu. get_diagnostics ( ) ;
378
+ if !diags. is_empty ( ) {
379
+ let mut has_error = false ;
380
+ eprintln ! ( "=== WARNING: {} diagnostic messages" , diags. len( ) ) ;
381
+ for diag in diags {
382
+ if !has_error && matches ! ( diag. get_severity( ) , Severity :: Error | Severity :: Fatal ) {
383
+ has_error = true ;
384
+ }
385
+ eprintln ! ( "=== {}" , diag) ;
386
+ }
387
+ if has_error && panic_on_error {
388
+ panic ! ( "=== Errors during header parsing" ) ;
389
+ }
390
+ }
375
391
entity_processor ( root_tu. get_entity ( ) ) ;
376
392
}
377
393
378
394
pub fn process_opencv_module ( & self , module : & str , visitor : impl for < ' gtu > GeneratorVisitor < ' gtu > ) {
379
- self . process_module ( module, |root_entity| {
395
+ self . process_module ( module, true , |root_entity| {
380
396
let gen_env = GeneratorEnv :: new ( root_entity, module) ;
381
397
let opencv_walker = OpenCVWalker :: new (
382
398
& self . opencv_include_dir ,
0 commit comments