2
0
mirror of synced 2025-02-23 06:48:15 +00:00

internal/importers/objc: fix parsing of newer clang output

Two things broke the clang ast dump parser:

- clang -cc1 didn't parse headers in iPhone mode automatically anymore.
  Add the -triple argument to force it.
- Source positions in the dumps can now contain <scratch space>.

Change-Id: I5d561f781355021f60c94d59e20bf1c1eee76d2a
Reviewed-on: https://go-review.googlesource.com/c/159678
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Elias Naur 2019-01-25 18:25:31 +01:00
parent 58b5a00d9a
commit 07b47c2b9c

View File

@ -412,7 +412,7 @@ const (
// file Module.framework/Headers/Module.h contains every declaration.
func importModule(sdkPath, module string, identifiers []string, typeMap map[string]*Named) ([]*Named, error) {
hFile := fmt.Sprintf(sdkPath+frameworksPath+"%s.framework/Headers/%[1]s.h", module)
clang := exec.Command("xcrun", "--sdk", "iphonesimulator", "clang", "-cc1", "-isysroot", sdkPath, "-ast-dump", "-fblocks", "-fobjc-arc", "-x", "objective-c", hFile)
clang := exec.Command("xcrun", "--sdk", "iphonesimulator", "clang", "-cc1", "-triple", "x86_64-apple-ios8.0.0-simulator", "-isysroot", sdkPath, "-ast-dump", "-fblocks", "-fobjc-arc", "-x", "objective-c", hFile)
out, err := clang.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("clang failed to parse module: %v: %s", err, out)
@ -774,9 +774,17 @@ func (p *parser) parseSrcPos() {
p.decl = p.decl[len(invPref):]
return
}
// line:17:2, col:18 or, a file location:
// /.../UIKit.framework/Headers/UISelectionFeedbackGenerator.h:16:1
loc := p.scanWord()
var loc string
const scrPref = "<scratch space>"
if strings.HasPrefix(p.decl, scrPref) {
// <scratch space>:130:1
p.decl = p.decl[len(scrPref):]
loc = "line" + p.scanWord()
} else {
// line:17:2, col:18 or, a file location:
// /.../UIKit.framework/Headers/UISelectionFeedbackGenerator.h:16:1
loc = p.scanWord()
}
locs := strings.SplitN(loc, ":", 2)
if len(locs) != 2 && len(locs) != 3 {
panic(fmt.Errorf("invalid source position: %q", loc))