Now that gofmt is reformatting these, we can't get away with
not knowing about directives such as //export and //extern (for gccgo).
Otherwise "//export foo" and "//extern foo" turn into "// export foo",
and "// extern foo", which are completely different meanings.
For #51082.
Change-Id: Id0970331fa0b52ab5fa621631b5fa460767068bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/399734
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
// This code is also in go/printer.
func isDirective(c string) bool {
// "//line " is a line directive.
+ // "//extern " is for gccgo.
+ // "//export " is for cgo.
// (The // has been removed.)
- if strings.HasPrefix(c, "line ") {
+ if strings.HasPrefix(c, "line ") || strings.HasPrefix(c, "extern ") || strings.HasPrefix(c, "export ") {
return true
}
{"go:", false},
{"go:*", false},
{"go:x*", true},
+ {"export foo", true},
+ {"extern foo", true},
+ {"expert foo", false},
}
func TestIsDirective(t *testing.T) {
// This code is also in go/ast.
func isDirective(c string) bool {
// "//line " is a line directive.
+ // "//extern " is for gccgo.
+ // "//export " is for cgo.
// (The // has been removed.)
- if strings.HasPrefix(c, "line ") {
+ if strings.HasPrefix(c, "line ") || strings.HasPrefix(c, "extern ") || strings.HasPrefix(c, "export ") {
return true
}
}
}
+//extern foo
+func foo() {}
+
+//export bar
+func bar() {}
+
// Print line directives correctly.
// The following is a legal line directive.
}
}
+//extern foo
+func foo() {}
+
+//export bar
+func bar() {}
+
// Print line directives correctly.
// The following is a legal line directive.