]> Cypherpunks.ru repositories - gostls13.git/blob - src/go/types/alias.go
f79d5eaf3a46e7e9d96244ca6ba51c2c6499ea95
[gostls13.git] / src / go / types / alias.go
1 // Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
2
3 // Copyright 2023 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 package types
8
9 import "fmt"
10
11 // Names starting with a _ are intended to be exported eventually
12 // (go.dev/issue/63223).
13
14 // An _Alias represents an alias type.
15 type _Alias struct {
16         obj     *TypeName // corresponding declared alias object
17         fromRHS Type      // RHS of type alias declaration; may be an alias
18         actual  Type      // actual (aliased) type; never an alias
19 }
20
21 // _NewAlias creates a new Alias type with the given type name and rhs.
22 // rhs must not be nil.
23 func _NewAlias(obj *TypeName, rhs Type) *_Alias {
24         return (*Checker)(nil).newAlias(obj, rhs)
25 }
26
27 func (a *_Alias) Underlying() Type { return a.actual.Underlying() }
28 func (a *_Alias) String() string   { return TypeString(a, nil) }
29
30 // Type accessors
31
32 // _Unalias returns t if it is not an alias type;
33 // otherwise it follows t's alias chain until it
34 // reaches a non-alias type which is then returned.
35 // Consequently, the result is never an alias type.
36 func _Unalias(t Type) Type {
37         if a0, _ := t.(*_Alias); a0 != nil {
38                 if a0.actual != nil {
39                         return a0.actual
40                 }
41                 for a := a0; ; {
42                         t = a.fromRHS
43                         a, _ = t.(*_Alias)
44                         if a == nil {
45                                 break
46                         }
47                 }
48                 if t == nil {
49                         panic(fmt.Sprintf("non-terminated alias %s", a0.obj.name))
50                 }
51                 a0.actual = t
52         }
53         return t
54 }
55
56 // asNamed returns t as *Named if that is t's
57 // actual type. It returns nil otherwise.
58 func asNamed(t Type) *Named {
59         n, _ := _Unalias(t).(*Named)
60         return n
61 }
62
63 // newAlias creates a new Alias type with the given type name and rhs.
64 // rhs must not be nil.
65 func (check *Checker) newAlias(obj *TypeName, rhs Type) *_Alias {
66         assert(rhs != nil)
67         a := &_Alias{obj, rhs, nil}
68         if obj.typ == nil {
69                 obj.typ = a
70         }
71
72         // Ensure that a.actual is set at the end of type checking.
73         if check != nil {
74                 check.needsCleanup(a)
75         }
76
77         return a
78 }
79
80 func (a *_Alias) cleanup() {
81         _Unalias(a)
82 }