]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types: generate more files from types2 sources
authorRobert Griesemer <gri@golang.org>
Mon, 9 Jan 2023 22:19:27 +0000 (14:19 -0800)
committerGopher Robot <gobot@golang.org>
Tue, 17 Jan 2023 19:55:39 +0000 (19:55 +0000)
Change-Id: I5e00b4367d7288867b03702d0c76b8210c125668
Reviewed-on: https://go-review.googlesource.com/c/go/+/461083
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>

src/go/types/array.go
src/go/types/basic.go
src/go/types/context_test.go
src/go/types/generator.go
src/go/types/instantiate_test.go
src/go/types/object.go
src/go/types/package.go
src/go/types/predicates.go
src/go/types/sizeof_test.go
src/go/types/typeterm_test.go
src/go/types/universe.go

index 5b28474bb339ec682481cf623c29399ad81b24bd..759e2f2e67096b047423b21488ac3cd72e39faea 100644 (file)
@@ -1,3 +1,5 @@
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
 // Copyright 2011 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.
@@ -21,5 +23,5 @@ func (a *Array) Len() int64 { return a.len }
 // Elem returns element type of array a.
 func (a *Array) Elem() Type { return a.elem }
 
-func (t *Array) Underlying() Type { return t }
-func (t *Array) String() string   { return TypeString(t, nil) }
+func (a *Array) Underlying() Type { return a }
+func (a *Array) String() string   { return TypeString(a, nil) }
index 215923f6573a560f422a2201b5330d6fe853094b..7d6decdb1ae36075086d82f6f4917b90bda1a654 100644 (file)
@@ -1,3 +1,5 @@
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
 // Copyright 2011 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.
@@ -78,5 +80,5 @@ func (b *Basic) Info() BasicInfo { return b.info }
 // Name returns the name of basic type b.
 func (b *Basic) Name() string { return b.name }
 
-func (t *Basic) Underlying() Type { return t }
-func (t *Basic) String() string   { return TypeString(t, nil) }
+func (b *Basic) Underlying() Type { return b }
+func (b *Basic) String() string   { return TypeString(b, nil) }
index b323651e29de855a95182cf1b9e7807a8187ca1c..1340bf20536f83567c496653a8ecc03ed0366a54 100644 (file)
@@ -1,3 +1,5 @@
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
 // Copyright 2021 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.
index 7b5c7f60e27c2b96bc40fd0f0c1545f2ad308800..2971b3051128d4d4638fd4b7e74bd72c080d4b59 100644 (file)
@@ -64,32 +64,43 @@ func main() {
 type action func(in *ast.File)
 
 var filemap = map[string]action{
-       "chan.go":          nil,
-       "context.go":       nil,
-       "gccgosizes.go":    nil,
-       "lookup.go":        nil,
-       "main_test.go":     nil,
-       "map.go":           nil,
-       "named.go":         func(f *ast.File) { fixTokenPos(f); fixTraceSel(f) },
-       "objset.go":        nil,
-       "pointer.go":       nil,
-       "selection.go":     nil,
-       "sizes.go":         func(f *ast.File) { rename(f, "IsSyncAtomicAlign64", "isSyncAtomicAlign64") },
-       "slice.go":         nil,
-       "subst.go":         func(f *ast.File) { fixTokenPos(f); fixTraceSel(f) },
-       "termlist.go":      nil,
-       "termlist_test.go": nil,
-       "tuple.go":         nil,
-       "typelists.go":     nil,
-       "typeparam.go":     nil,
-       "typeterm.go":      nil,
-       "validtype.go":     nil,
+       "array.go":            nil,
+       "basic.go":            nil,
+       "chan.go":             nil,
+       "context.go":          nil,
+       "context_test.go":     nil,
+       "gccgosizes.go":       nil,
+       "instantiate_test.go": func(f *ast.File) { renameImportPath(f, `"cmd/compile/internal/types2"`, `"go/types"`) },
+       "lookup.go":           nil,
+       "main_test.go":        nil,
+       "map.go":              nil,
+       "named.go":            func(f *ast.File) { fixTokenPos(f); fixTraceSel(f) },
+       "object.go":           func(f *ast.File) { fixTokenPos(f); renameIdent(f, "NewTypeNameLazy", "_NewTypeNameLazy") },
+       "objset.go":           nil,
+       "package.go":          nil,
+       "pointer.go":          nil,
+       "predicates.go":       nil,
+       "selection.go":        nil,
+       "sizes.go":            func(f *ast.File) { renameIdent(f, "IsSyncAtomicAlign64", "isSyncAtomicAlign64") },
+       "slice.go":            nil,
+       "subst.go":            func(f *ast.File) { fixTokenPos(f); fixTraceSel(f) },
+       "termlist.go":         nil,
+       "termlist_test.go":    nil,
+       "tuple.go":            nil,
+       "typelists.go":        nil,
+       "typeparam.go":        nil,
+       "typeterm_test.go":    nil,
+       "typeterm.go":         nil,
+       "universe.go":         fixGlobalTypVarDecl,
+       "validtype.go":        nil,
 }
 
 // TODO(gri) We should be able to make these rewriters more configurable/composable.
 //           For now this is a good starting point.
 
-func rename(f *ast.File, from, to string) {
+// renameIdent renames an identifier.
+// Note: This doesn't change the use of the identifier in comments.
+func renameIdent(f *ast.File, from, to string) {
        ast.Inspect(f, func(n ast.Node) bool {
                switch n := n.(type) {
                case *ast.Ident:
@@ -102,6 +113,22 @@ func rename(f *ast.File, from, to string) {
        })
 }
 
+// renameImportPath renames an import path.
+func renameImportPath(f *ast.File, from, to string) {
+       ast.Inspect(f, func(n ast.Node) bool {
+               switch n := n.(type) {
+               case *ast.ImportSpec:
+                       if n.Path.Kind == token.STRING && n.Path.Value == from {
+                               n.Path.Value = to
+                               return false
+                       }
+               }
+               return true
+       })
+}
+
+// fixTokenPos changes imports of "cmd/compile/internal/syntax" to "go/token"
+// and uses of syntax.Pos to token.Pos.
 func fixTokenPos(f *ast.File) {
        ast.Inspect(f, func(n ast.Node) bool {
                switch n := n.(type) {
@@ -120,6 +147,7 @@ func fixTokenPos(f *ast.File) {
        })
 }
 
+// fixTraceSel renames uses of x.Trace to x.trace, where x for any x with a Trace field.
 func fixTraceSel(f *ast.File) {
        ast.Inspect(f, func(n ast.Node) bool {
                switch n := n.(type) {
@@ -132,3 +160,19 @@ func fixTraceSel(f *ast.File) {
                return true
        })
 }
+
+// fixGlobalTypVarDecl changes the global Typ variable from an array to a slice
+// (in types2 we use an array for efficiency, in go/types it's a slice and we
+// cannot change that).
+func fixGlobalTypVarDecl(f *ast.File) {
+       ast.Inspect(f, func(n ast.Node) bool {
+               switch n := n.(type) {
+               case *ast.ValueSpec:
+                       if len(n.Names) == 1 && n.Names[0].Name == "Typ" && len(n.Values) == 1 {
+                               n.Values[0].(*ast.CompositeLit).Type.(*ast.ArrayType).Len = nil
+                               return false
+                       }
+               }
+               return true
+       })
+}
index 8b551187bd9342569178b60c16b771740ed757db..54e725fc972dffbd65a84e36bd5015484216006b 100644 (file)
@@ -1,7 +1,8 @@
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
 // Copyright 2021 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 types_test
 
 import (
@@ -134,15 +135,12 @@ func TestInstantiateEquality(t *testing.T) {
 
 func TestInstantiateNonEquality(t *testing.T) {
        const src = "package p; type T[P any] int"
-
        pkg1 := mustTypecheck(".", src, nil)
        pkg2 := mustTypecheck(".", src, nil)
-
        // We consider T1 and T2 to be distinct types, so their instances should not
        // be deduplicated by the context.
        T1 := pkg1.Scope().Lookup("T").Type().(*Named)
        T2 := pkg2.Scope().Lookup("T").Type().(*Named)
-
        ctxt := NewContext()
        res1, err := Instantiate(ctxt, T1, []Type{Typ[Int]}, false)
        if err != nil {
@@ -152,7 +150,6 @@ func TestInstantiateNonEquality(t *testing.T) {
        if err != nil {
                t.Fatal(err)
        }
-
        if res1 == res2 {
                t.Errorf("instance from pkg1 (%s) is pointer-equivalent to instance from pkg2 (%s)", res1, res2)
        }
index 3013552bf567366d126cc17f5327228c67863aaa..74b630af9e078986ea79c0adbbb1ddc2d45de2b5 100644 (file)
@@ -1,3 +1,5 @@
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
 // Copyright 2013 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.
@@ -9,6 +11,8 @@ import (
        "fmt"
        "go/constant"
        "go/token"
+       "unicode"
+       "unicode/utf8"
 )
 
 // An Object describes a named language entity such as a package,
@@ -57,10 +61,15 @@ type Object interface {
        setScopePos(pos token.Pos)
 }
 
+func isExported(name string) bool {
+       ch, _ := utf8.DecodeRuneInString(name)
+       return unicode.IsUpper(ch)
+}
+
 // Id returns name if it is exported, otherwise it
 // returns the name qualified with the package path.
 func Id(pkg *Package, name string) string {
-       if token.IsExported(name) {
+       if isExported(name) {
                return name
        }
        // unexported names need the package path for differentiation
@@ -140,7 +149,7 @@ func (obj *object) Type() Type { return obj.typ }
 // Exported reports whether the object is exported (starts with a capital letter).
 // It doesn't take into account whether the object is in a local (function) scope
 // or not.
-func (obj *object) Exported() bool { return token.IsExported(obj.name) }
+func (obj *object) Exported() bool { return isExported(obj.name) }
 
 // Id is a wrapper for Id(obj.Pkg(), obj.Name()).
 func (obj *object) Id() string { return Id(obj.pkg, obj.name) }
@@ -178,6 +187,42 @@ func (obj *object) sameId(pkg *Package, name string) bool {
        return pkg.path == obj.pkg.path
 }
 
+// less reports whether object a is ordered before object b.
+//
+// Objects are ordered nil before non-nil, exported before
+// non-exported, then by name, and finally (for non-exported
+// functions) by package path.
+func (a *object) less(b *object) bool {
+       if a == b {
+               return false
+       }
+
+       // Nil before non-nil.
+       if a == nil {
+               return true
+       }
+       if b == nil {
+               return false
+       }
+
+       // Exported functions before non-exported.
+       ea := isExported(a.name)
+       eb := isExported(b.name)
+       if ea != eb {
+               return ea
+       }
+
+       // Order by name and then (for non-exported names) by package.
+       if a.name != b.name {
+               return a.name < b.name
+       }
+       if !ea {
+               return a.pkg.path < b.pkg.path
+       }
+
+       return false
+}
+
 // A PkgName represents an imported Go package.
 // PkgNames don't have a type.
 type PkgName struct {
@@ -229,7 +274,7 @@ func NewTypeName(pos token.Pos, pkg *Package, name string, typ Type) *TypeName {
        return &TypeName{object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}}
 }
 
-// _NewTypeNameLazy returns a new defined type like NewTypeName, but it
+// NewTypeNameLazy returns a new defined type like NewTypeName, but it
 // lazily calls resolve to finish constructing the Named object.
 func _NewTypeNameLazy(pos token.Pos, pkg *Package, name string, load func(named *Named) (tparams []*TypeParam, underlying Type, methods []*Func)) *TypeName {
        obj := NewTypeName(pos, pkg, name, nil)
index 201f603234459d1a0a4dd65edc753ad17061d395..7a64aa9fe4c6a734dcf4943186fdd395f5350748 100644 (file)
@@ -1,3 +1,5 @@
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
 // Copyright 2013 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.
@@ -13,8 +15,8 @@ type Package struct {
        path     string
        name     string
        scope    *Scope
-       complete bool
        imports  []*Package
+       complete bool
        fake     bool // scope lookup errors are silently dropped if package is fake (internal use only)
        cgo      bool // uses of this package will be rewritten into uses of declarations from _cgo_gotypes.go
 }
index b26b5beb9cb90dd5e13b300015c3cfcf18dfc328..c80d41d702e51d368b7b0c441978dfbc05e5a08f 100644 (file)
@@ -1,3 +1,5 @@
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
 // Copyright 2012 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.
@@ -34,13 +36,13 @@ func isBasic(t Type, info BasicInfo) bool {
 // allX is an optimized version of isX(coreType(t)) (which
 // is the same as underIs(t, isX)).
 
-func allBoolean(typ Type) bool         { return allBasic(typ, IsBoolean) }
-func allInteger(typ Type) bool         { return allBasic(typ, IsInteger) }
-func allUnsigned(typ Type) bool        { return allBasic(typ, IsUnsigned) }
-func allNumeric(typ Type) bool         { return allBasic(typ, IsNumeric) }
-func allString(typ Type) bool          { return allBasic(typ, IsString) }
-func allOrdered(typ Type) bool         { return allBasic(typ, IsOrdered) }
-func allNumericOrString(typ Type) bool { return allBasic(typ, IsNumeric|IsString) }
+func allBoolean(t Type) bool         { return allBasic(t, IsBoolean) }
+func allInteger(t Type) bool         { return allBasic(t, IsInteger) }
+func allUnsigned(t Type) bool        { return allBasic(t, IsUnsigned) }
+func allNumeric(t Type) bool         { return allBasic(t, IsNumeric) }
+func allString(t Type) bool          { return allBasic(t, IsString) }
+func allOrdered(t Type) bool         { return allBasic(t, IsOrdered) }
+func allNumericOrString(t Type) bool { return allBasic(t, IsNumeric|IsString) }
 
 // allBasic reports whether under(t) is a basic type with the specified info.
 // If t is a type parameter, the result is true if isBasic(t, info) is true
index d4ce0a7fcd0a4d362fa356a3785538833c7ad057..f17a1781f574483e7ed3d71ff9f9765c957d6019 100644 (file)
@@ -46,7 +46,7 @@ func TestSizeof(t *testing.T) {
 
                // Misc
                {Scope{}, 44, 88},
-               {Package{}, 40, 80},
+               {Package{}, 36, 72},
                {_TypeSet{}, 28, 56},
        }
        for _, test := range tests {
index 683b95ee56f2faee5d136aab7fea9dae3859e580..bf67f3872ddce885cfc41a6b463655f8adbcec56 100644 (file)
@@ -1,3 +1,5 @@
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
 // Copyright 2021 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.
index 8860aadfcab0192a5aebbc057db6cf148ed8e826..6984cf849b7fdf95acbdb0ab9e8d24ca07c58bd2 100644 (file)
@@ -1,3 +1,5 @@
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
 // Copyright 2011 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.