aboutsummaryrefslogtreecommitdiffhomepage
path: root/cgo
AgeCommit message (Collapse)Author
2019-11-25cgo: implement #cgo CFLAGSAyke van Laethem
This implementation is still very limited but provides a base to build upon. Limitations: * CGO_CFLAGS etc is not taken into account. * These CFLAGS are not used in C files compiled with the package. * Other flags (CPPFLAGS, LDFAGS, ...) are not yet implemented.
2019-11-25cgo: add tests for errorsAyke van Laethem
This commit adds tests for CGo preprocessing. There are various errors that can be reported while preprocessing, and they should integrate well with the compiler (including accurate source location tracking). Also allow CGo preprocessing to continue after Clang encountered an error, for a better view of what happened.
2019-11-16all: switch to LLVM 9Ayke van Laethem
2019-11-08cgo: add -update flag to testsAyke van Laethem
When this flag is set, the testdata/*.out.go files will be updated when they have changed. This is very convenient for updating these files after the expected output changes. Of course, the updated output must still be checked for validity.
2019-11-08cgo: add support for nested structs and unionsAyke van Laethem
2019-11-07cgo: refactor union supportAyke van Laethem
Instead of putting the magic in the AST, generate regular accessor methods. This avoids a number of special cases in the compiler, and avoids missing any of them. The resulting union accesses are somewhat clunkier to use, but the compiler implementation has far less coupling between the CGo implementation and the IR generator.
2019-11-06cgo: include all enums in the CGo Go ASTAyke van Laethem
Not all enums may be used as a type anywhere, which was previously the only way to include an enum in the AST. This commit makes sure all enums are included.
2019-11-06cgo: do type checking in CGo testingAyke van Laethem
Such type checking should hopefully catch more bugs. This commit also fixes some existing type errors.
2019-11-06cgo: avoid '"unsafe" imported but not used' errorAyke van Laethem
This can happen when not all CGo features are used.
2019-11-06cgo: rename reserved field names like `type`Ayke van Laethem
This commit renames reserved field names like `type` to `_type`, and in turn renames those fields as well (recursively). This avoids name clashes when a C struct contains a field named `type`, which is a reserved keyword in Go. For some details, see: https://golang.org/cmd/cgo/#hdr-Go_references_to_C
2019-11-05cgo: implement the constant parser as a real parserAyke van Laethem
Previously it was just a combination of heuristics to try to fit a constant in an *ast.BasicLit. For more complex expressions, this is not enough. This change also introduces proper syntax error with locations, if parsing a constant failed. For example, this will print a real error message with source location: #define FOO 5)
2019-11-05cgo: refactor constant expressionsAyke van Laethem
Put them in a separate file for separation of concerns (making them testable) and add some tests.
2019-11-03macos: use llvm@8 instead of just llvm in pathsAyke van Laethem
This should hopefully avoid needing to use `brew switch`.
2019-11-03cgo: add tests for most C typesAyke van Laethem
2019-11-03cgo: add bare-bones testAyke van Laethem
2019-11-03cgo: create new GenDecl for every symbolAyke van Laethem
Previously, a GenDecl was shared between many different consts/vars/types. However, it actually makes much more sense not to bundle them as that is also the case in C. This makes the printed output of the CGo AST much nicer, and works around a bug in Go 1.11.
2019-11-03cgo: improve diagnosticsAyke van Laethem
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.
2019-06-03cgo: add support for anonymous structsAyke van Laethem
2019-06-03cgo: add support for bitfields using generated getters and settersAyke van Laethem
2019-05-17cgo: print better error messages for unknown typesAyke van Laethem
Types used in a program may not be implemented. Print a nice error message explaining the situation, instead of just prepending C. to the type spelling (and hoping the user knows what that undefined reference means).
2019-05-17cgo: add support for enum typesAyke van Laethem
Enum types are implemented as named types (with possible accompanying typedefs as type aliases). The constants inside the enums are treated as Go constants like in the Go toolchain.
2019-05-13Trivial typo fixesJustin Clift
2019-05-12cgo: refactor; support multiple cgo files in a single packageAyke van Laethem
This is a big commit that does a few things: * It moves CGo processing into a separate package. It never really belonged in the loader package, and certainly not now that the loader package may be refactored into a driver package. * It adds support for multiple CGo files (files that import package "C") in a single package. Previously, this led to multiple definition errors in the Go typecheck phase because certain C symbols were defined multiple times in all the files. Now it generates a new fake AST that defines these, to avoid multiple definition errors. * It improves debug info in a few edge cases that are probably not relevant outside of bugs in cgo itself.