Skip to content

Commit

Permalink
check for and report errors when parsing translation unit
Browse files Browse the repository at this point in the history
  • Loading branch information
glowcoil committed Jul 18, 2023
1 parent 51a0146 commit 4dbf19b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 19 additions & 0 deletions com-scrape/src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ impl TranslationUnit {
return Err("error building translation unit".into());
}

let mut has_error = false;
let mut error = String::new();
let num_diagnostics = clang_getNumDiagnostics(unit) as usize;
for i in 0..num_diagnostics {
let diagnostic = clang_getDiagnostic(unit, i as c_uint);
if clang_getDiagnosticSeverity(diagnostic) >= CXDiagnostic_Error {
has_error = true;

let opts = clang_defaultDiagnosticDisplayOptions();
let str = StringRef::from_raw(clang_formatDiagnostic(diagnostic, opts));
error.push_str(str.to_str().unwrap());
error.push('\n');
}
}
if has_error {
clang_disposeIndex(index);
return Err(error.into());
}

Ok(TranslationUnit { index, unit })
}
}
Expand Down
3 changes: 1 addition & 2 deletions com-scrape/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ impl Generator {
source.as_ref(),
&self.include_paths,
clang_target.as_deref(),
)
.unwrap();
)?;

let namespace = Namespace::parse(&unit.cursor(), &self)?;

Expand Down

0 comments on commit 4dbf19b

Please sign in to comment.