2015-02-13 14:40:36 -05:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package gc
|
|
|
|
|
|
|
|
|
|
import (
|
2016-03-11 13:39:20 -05:00
|
|
|
"bufio"
|
2015-08-13 19:05:37 -07:00
|
|
|
"bytes"
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
"cmd/compile/internal/types"
|
2016-04-06 21:45:29 -07:00
|
|
|
"cmd/internal/bio"
|
2017-08-28 13:02:58 -07:00
|
|
|
"cmd/internal/src"
|
2015-02-13 14:40:36 -05:00
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
2015-08-13 19:05:37 -07:00
|
|
|
var (
|
2016-08-16 12:55:17 -07:00
|
|
|
Debug_export int // if set, print debugging information about export data
|
2015-08-13 19:05:37 -07:00
|
|
|
)
|
|
|
|
|
|
2017-08-30 17:43:19 -07:00
|
|
|
func exportf(bout *bio.Writer, format string, args ...interface{}) {
|
2017-03-13 14:30:44 +11:00
|
|
|
fmt.Fprintf(bout, format, args...)
|
2015-08-13 19:05:37 -07:00
|
|
|
if Debug_export != 0 {
|
|
|
|
|
fmt.Printf(format, args...)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-04 19:04:50 -08:00
|
|
|
var asmlist []*Node
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2018-04-02 15:38:57 -07:00
|
|
|
// exportsym marks n for export (or reexport).
|
2015-02-13 14:40:36 -05:00
|
|
|
func exportsym(n *Node) {
|
2018-04-02 15:38:57 -07:00
|
|
|
if n.Sym.OnExportList() {
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
2018-04-02 15:38:57 -07:00
|
|
|
n.Sym.SetOnExportList(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
if Debug['E'] != 0 {
|
2018-04-02 16:15:25 -07:00
|
|
|
fmt.Printf("export symbol %v\n", n.Sym)
|
cmd/compile: simplify reexport logic
Currently, we reexport any package-scope constant, function, type, or
variable declarations needed by an inlineable function body. However,
now that we have an early pass to walk inlineable function bodies
(golang.org/cl/74110), we can simplify the logic for finding these
declarations.
The binary export format supports writing out type declarations
in-place at their first use. Also, it always writes out constants by
value, so their declarations never need to be reexported.
Notably, we attempted this before (golang.org/cl/36170) and had to
revert it (golang.org/cl/45911). However, this was because while
writing out inline bodies, we could discover variable/function
dependencies. By collecting variable/function dependencies during
inlineable function discovery, we avoid this problem.
While here, get rid of isInlineable. We already typecheck inlineable
function bodies during inlFlood, so it's become a no-op. Just move the
comment explaining parameter numbering to its caller.
Change-Id: Ibbfaafce793733675d3a2ad98791758583055666
Reviewed-on: https://go-review.googlesource.com/103864
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-30 18:58:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exportlist = append(exportlist, n)
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
func initname(s string) bool {
|
|
|
|
|
return s == "init"
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-10-26 14:57:36 -07:00
|
|
|
func autoexport(n *Node, ctxt Class) {
|
2018-04-02 15:38:57 -07:00
|
|
|
if n.Sym.Pkg != localpkg {
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (ctxt != PEXTERN && ctxt != PFUNC) || dclcontext != PEXTERN {
|
|
|
|
|
return
|
|
|
|
|
}
|
2017-10-20 11:56:31 +01:00
|
|
|
if n.Type != nil && n.Type.IsKind(TFUNC) && n.IsMethod() {
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-09 15:22:01 -07:00
|
|
|
if types.IsExported(n.Sym.Name) || initname(n.Sym.Name) {
|
2015-02-13 14:40:36 -05:00
|
|
|
exportsym(n)
|
|
|
|
|
}
|
2018-04-02 15:38:57 -07:00
|
|
|
if asmhdr != "" && !n.Sym.Asm() {
|
2017-03-06 20:00:54 +02:00
|
|
|
n.Sym.SetAsm(true)
|
2016-03-04 19:04:50 -08:00
|
|
|
asmlist = append(asmlist, n)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-14 20:53:44 +02:00
|
|
|
// methodbyname sorts types by symbol name.
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
type methodbyname []*types.Field
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-09-14 20:53:44 +02:00
|
|
|
func (x methodbyname) Len() int { return len(x) }
|
|
|
|
|
func (x methodbyname) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
|
|
|
|
func (x methodbyname) Less(i, j int) bool { return x[i].Sym.Name < x[j].Sym.Name }
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2017-08-30 17:43:19 -07:00
|
|
|
func dumpexport(bout *bio.Writer) {
|
2015-08-13 19:05:37 -07:00
|
|
|
size := 0 // size of export section without enclosing markers
|
2016-08-16 12:55:17 -07:00
|
|
|
// The linker also looks for the $$ marker - use char after $$ to distinguish format.
|
2017-08-30 17:43:19 -07:00
|
|
|
exportf(bout, "\n$$B\n") // indicate binary export format
|
2016-08-16 12:55:17 -07:00
|
|
|
if debugFormat {
|
|
|
|
|
// save a copy of the export data
|
|
|
|
|
var copy bytes.Buffer
|
|
|
|
|
bcopy := bufio.NewWriter(©)
|
|
|
|
|
size = export(bcopy, Debug_export != 0)
|
|
|
|
|
bcopy.Flush() // flushing to bytes.Buffer cannot fail
|
|
|
|
|
if n, err := bout.Write(copy.Bytes()); n != size || err != nil {
|
|
|
|
|
Fatalf("error writing export data: got %d bytes, want %d bytes, err = %v", n, size, err)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
2016-08-16 12:55:17 -07:00
|
|
|
// export data must contain no '$' so that we can find the end by searching for "$$"
|
|
|
|
|
// TODO(gri) is this still needed?
|
|
|
|
|
if bytes.IndexByte(copy.Bytes(), '$') >= 0 {
|
|
|
|
|
Fatalf("export data contains $")
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-16 12:55:17 -07:00
|
|
|
// verify that we can read the copied export data back in
|
|
|
|
|
// (use empty package map to avoid collisions)
|
2017-04-19 11:32:09 -07:00
|
|
|
types.CleanroomDo(func() {
|
|
|
|
|
Import(types.NewPkg("", ""), bufio.NewReader(©)) // must not die
|
|
|
|
|
})
|
2016-08-16 12:55:17 -07:00
|
|
|
} else {
|
|
|
|
|
size = export(bout.Writer, Debug_export != 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2017-08-30 17:43:19 -07:00
|
|
|
exportf(bout, "\n$$\n")
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-08-13 19:05:37 -07:00
|
|
|
if Debug_export != 0 {
|
|
|
|
|
fmt.Printf("export data size = %d bytes\n", size)
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-04-04 15:41:56 -07:00
|
|
|
// importsym declares symbol s as an imported object representable by op.
|
2017-03-23 17:39:28 -07:00
|
|
|
// pkg is the package being imported
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func importsym(pkg *types.Pkg, s *types.Sym, op Op) {
|
|
|
|
|
if asNode(s.Def) != nil && asNode(s.Def).Op != op {
|
2017-03-23 17:39:28 -07:00
|
|
|
pkgstr := fmt.Sprintf("during import %q", pkg.Path)
|
2018-04-02 17:33:38 -07:00
|
|
|
redeclare(lineno, s, pkgstr)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-04 15:41:56 -07:00
|
|
|
// pkgtype returns the named type declared by symbol s.
|
|
|
|
|
// If no such type has been declared yet, a forward declaration is returned.
|
2017-03-23 17:39:28 -07:00
|
|
|
// pkg is the package being imported
|
2017-08-28 13:02:58 -07:00
|
|
|
func pkgtype(pos src.XPos, pkg *types.Pkg, s *types.Sym) *types.Type {
|
2017-03-23 17:39:28 -07:00
|
|
|
importsym(pkg, s, OTYPE)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if asNode(s.Def) == nil || asNode(s.Def).Op != OTYPE {
|
|
|
|
|
t := types.New(TFORW)
|
2015-02-13 14:40:36 -05:00
|
|
|
t.Sym = s
|
2017-08-28 13:02:58 -07:00
|
|
|
s.Def = asTypesNode(typenodl(pos, t))
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
asNode(s.Def).Name = new(Name)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if asNode(s.Def).Type == nil {
|
2017-03-14 09:46:45 -07:00
|
|
|
Fatalf("pkgtype %v", s)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
return asNode(s.Def).Type
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2018-04-02 17:33:38 -07:00
|
|
|
// importconst declares symbol s as an imported constant with type t and value val.
|
2017-03-23 17:39:28 -07:00
|
|
|
// pkg is the package being imported
|
2018-04-02 17:33:38 -07:00
|
|
|
func importconst(pos src.XPos, pkg *types.Pkg, s *types.Sym, t *types.Type, val Val) {
|
2017-03-23 17:39:28 -07:00
|
|
|
importsym(pkg, s, OLITERAL)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if asNode(s.Def) != nil { // TODO: check if already the same.
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-02 17:33:38 -07:00
|
|
|
n := npos(pos, nodlit(val))
|
2018-04-07 03:08:46 -07:00
|
|
|
n.Type = t
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Sym = s
|
|
|
|
|
declare(n, PEXTERN)
|
|
|
|
|
|
|
|
|
|
if Debug['E'] != 0 {
|
2015-04-17 12:03:22 -04:00
|
|
|
fmt.Printf("import const %v\n", s)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-04 15:41:56 -07:00
|
|
|
// importvar declares symbol s as an imported variable with type t.
|
2017-03-23 17:39:28 -07:00
|
|
|
// pkg is the package being imported
|
2017-08-28 13:02:58 -07:00
|
|
|
func importvar(pos src.XPos, pkg *types.Pkg, s *types.Sym, t *types.Type) {
|
2017-03-23 17:39:28 -07:00
|
|
|
importsym(pkg, s, ONAME)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if asNode(s.Def) != nil && asNode(s.Def).Op == ONAME {
|
|
|
|
|
if eqtype(t, asNode(s.Def).Type) {
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
yyerror("inconsistent definition for var %v during import\n\t%v (in %q)\n\t%v (in %q)", s, asNode(s.Def).Type, s.Importdef.Path, t, pkg.Path)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2017-08-28 13:02:58 -07:00
|
|
|
n := newnamel(pos, s)
|
2017-03-23 17:39:28 -07:00
|
|
|
s.Importdef = pkg
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Type = t
|
|
|
|
|
declare(n, PEXTERN)
|
|
|
|
|
|
|
|
|
|
if Debug['E'] != 0 {
|
2016-09-09 21:08:46 -07:00
|
|
|
fmt.Printf("import var %v %L\n", s, t)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 11:24:35 -08:00
|
|
|
// importalias declares symbol s as an imported type alias with type t.
|
2017-03-23 17:39:28 -07:00
|
|
|
// pkg is the package being imported
|
2017-08-28 13:02:58 -07:00
|
|
|
func importalias(pos src.XPos, pkg *types.Pkg, s *types.Sym, t *types.Type) {
|
2017-03-23 17:39:28 -07:00
|
|
|
importsym(pkg, s, OTYPE)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if asNode(s.Def) != nil && asNode(s.Def).Op == OTYPE {
|
|
|
|
|
if eqtype(t, asNode(s.Def).Type) {
|
2017-01-11 11:24:35 -08:00
|
|
|
return
|
|
|
|
|
}
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
yyerror("inconsistent definition for type alias %v during import\n\t%v (in %q)\n\t%v (in %q)", s, asNode(s.Def).Type, s.Importdef.Path, t, pkg.Path)
|
2017-01-11 11:24:35 -08:00
|
|
|
}
|
|
|
|
|
|
2017-08-28 13:02:58 -07:00
|
|
|
n := newnamel(pos, s)
|
2017-01-11 11:24:35 -08:00
|
|
|
n.Op = OTYPE
|
2017-03-23 17:39:28 -07:00
|
|
|
s.Importdef = pkg
|
2017-01-11 11:24:35 -08:00
|
|
|
n.Type = t
|
|
|
|
|
declare(n, PEXTERN)
|
|
|
|
|
|
|
|
|
|
if Debug['E'] != 0 {
|
|
|
|
|
fmt.Printf("import type %v = %L\n", s, t)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
func dumpasmhdr() {
|
2016-04-06 21:45:29 -07:00
|
|
|
b, err := bio.Create(asmhdr)
|
2015-02-13 14:40:36 -05:00
|
|
|
if err != nil {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("%v", err)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-04 19:04:50 -08:00
|
|
|
fmt.Fprintf(b, "// generated by compile -asmhdr from package %s\n\n", localpkg.Name)
|
|
|
|
|
for _, n := range asmlist {
|
2017-04-21 07:51:41 -07:00
|
|
|
if n.Sym.IsBlank() {
|
2015-02-13 14:40:36 -05:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
switch n.Op {
|
|
|
|
|
case OLITERAL:
|
2016-08-30 15:01:48 -07:00
|
|
|
fmt.Fprintf(b, "#define const_%s %#v\n", n.Sym.Name, n.Val())
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case OTYPE:
|
2016-03-04 19:04:50 -08:00
|
|
|
t := n.Type
|
2016-04-01 20:11:30 -07:00
|
|
|
if !t.IsStruct() || t.StructType().Map != nil || t.IsFuncArgStruct() {
|
2015-02-13 14:40:36 -05:00
|
|
|
break
|
|
|
|
|
}
|
2017-11-29 11:58:03 -08:00
|
|
|
fmt.Fprintf(b, "#define %s__size %d\n", n.Sym.Name, int(t.Width))
|
|
|
|
|
for _, f := range t.Fields().Slice() {
|
|
|
|
|
if !f.Sym.IsBlank() {
|
|
|
|
|
fmt.Fprintf(b, "#define %s_%s %d\n", n.Sym.Name, f.Sym.Name, int(f.Offset))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-06 21:45:29 -07:00
|
|
|
b.Close()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|