cgo: add file AST for fake C file locations

This is needed for the type checker, otherwise it doesn't know which Go
version it should use for type checking.
This commit is contained in:
Ayke van Laethem
2024-01-17 15:55:07 +01:00
parent 0ad15551c8
commit 53db436a7d
5 changed files with 38 additions and 6 deletions
+7
View File
@@ -589,6 +589,13 @@ func (p *cgoPackage) getClangLocationPosition(location C.CXSourceLocation, tu C.
f := p.fset.AddFile(filename, -1, int(size))
f.SetLines(lines)
p.tokenFiles[filename] = f
// Add dummy file AST, to satisfy the type checker.
astFile := &ast.File{
Package: f.Pos(0),
Name: ast.NewIdent(p.packageName),
}
setASTFileFields(astFile, f.Pos(0), f.Pos(int(size)))
p.cgoFiles = append(p.cgoFiles, astFile)
}
positionFile := p.tokenFiles[filename]