aboutsummaryrefslogtreecommitdiffhomepage
path: root/cgo/libclang.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-09-22 23:03:05 +0200
committerRon Evans <[email protected]>2021-11-04 22:26:33 +0100
commitcceb6558743ee62f3580ed7586564373978b29f1 (patch)
treecf1cfdb87bab714a1d6a6165c5bba1351618626c /cgo/libclang.go
parent13891d428f18dbbe24fe16be8b18e7d912f71976 (diff)
downloadtinygo-cceb6558743ee62f3580ed7586564373978b29f1.tar.gz
tinygo-cceb6558743ee62f3580ed7586564373978b29f1.zip
cgo: run CGo parser for all CGo fragments in a file
Previously, libclang was run on each fragment (import "C") separately. However, in regular Go it's possible for later fragments to refer to types in earlier fragments so they must have been parsed as one. This commit changes the behavior to run only one C parser invocation for each Go file.
Diffstat (limited to 'cgo/libclang.go')
-rw-r--r--cgo/libclang.go9
1 files changed, 3 insertions, 6 deletions
diff --git a/cgo/libclang.go b/cgo/libclang.go
index 66f81c3d4..357bfd529 100644
--- a/cgo/libclang.go
+++ b/cgo/libclang.go
@@ -72,17 +72,14 @@ var diagnosticSeverity = [...]string{
C.CXDiagnostic_Fatal: "fatal",
}
-func (p *cgoPackage) parseFragment(fragment string, cflags []string, posFilename string, posLine int) {
+func (p *cgoPackage) parseFragment(fragment string, cflags []string, filename string) {
index := C.clang_createIndex(0, 0)
defer C.clang_disposeIndex(index)
// pretend to be a .c file
- filenameC := C.CString(posFilename + "!cgo.c")
+ filenameC := C.CString(filename + "!cgo.c")
defer C.free(unsafe.Pointer(filenameC))
- // fix up error locations
- fragment = fmt.Sprintf("# %d %#v\n", posLine, posFilename) + fragment
-
fragmentC := C.CString(fragment)
defer C.free(unsafe.Pointer(fragmentC))
@@ -380,7 +377,7 @@ func (p *cgoPackage) addErrorAfter(pos token.Pos, after, msg string) {
func (p *cgoPackage) addErrorAt(position token.Position, msg string) {
if filepath.IsAbs(position.Filename) {
// Relative paths for readability, like other Go parser errors.
- relpath, err := filepath.Rel(p.dir, position.Filename)
+ relpath, err := filepath.Rel(p.currentDir, position.Filename)
if err == nil {
position.Filename = relpath
}