cgo: improve diagnostics

This commit improves diagnostics in a few ways:

  * All panics apart from panics with no (easy) recovery are converted to
    regular errors with source location.
  * Some errors were improved slightly to give more information. For
    example, show the libclang type kind as a string instead of a
    number.
  * Improve source location by respecting line directives in the C
    preprocessor.
  * Refactor to unify error handling between libclang diagnostics and
    failures to parse the libclang AST.
This commit is contained in:
Ayke van Laethem
2019-06-03 14:48:05 +02:00
committed by Ron Evans
parent 86ab03c999
commit c138a50457
2 changed files with 83 additions and 53 deletions
+3
View File
@@ -131,6 +131,7 @@ var builtinAliases = map[string]struct{}{
// somehow from C. This is done by adding some typedefs to get the size of each
// type.
const cgoTypes = `
# 1 "<cgo>"
typedef char _Cgo_char;
typedef signed char _Cgo_schar;
typedef unsigned char _Cgo_uchar;
@@ -220,6 +221,8 @@ func Process(files []*ast.File, dir string, fset *token.FileSet, cflags []string
}
path, err := strconv.Unquote(spec.Path.Value)
if err != nil {
// This should not happen. An import path that is not properly
// quoted should not exist in a correct AST.
panic("could not parse import path: " + err.Error())
}
if path != "C" {