Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(75)

Side by Side Diff: src/pkg/go/types/types.go

Issue 4314054: code review 4314054: go/types: New Go type hierarchy implementation for AST. (Closed)
Patch Set: diff -r fd6ade18359d https://go.googlecode.com/hg/ Created 13 years, 12 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // PACKAGE UNDER CONSTRUCTION.
6 // The types package declares the types used to represent Go types.
7 //
8 package types
9
10 import "go/ast"
11
12
13 // All types implement the Type interface.
rsc 2011/04/07 16:27:19 Is the intent to expand this? If so would the isT
gri 2011/04/08 02:41:32 For now this is just here to ensure that we only s
14 type Type interface {
15 isType()
16 }
17
18
19 // All concrete types embed ImplementsType which
20 // ensures that all types implement the Type interface.
21 type ImplementsType struct{}
22
23 func (t *ImplementsType) isType() {}
24
25
26 // A Basic represents a (unnamed) basic type.
27 // Predeclared types have a basic type as underlying type.
28 type Basic struct {
29 ImplementsType
30 // TODO(gri) need a field specifying the exact basic type
31 }
32
33
34 // An Array represents an array type [Len]Elt.
35 type Array struct {
36 ImplementsType
37 Len uint64
38 Elt Type
39 }
40
41
42 // A Slice represents a slice type []Elt or ...Elt.
43 type Slice struct {
44 ImplementsType
45 Ellipsis bool // true for "...Elt" types
rsc 2011/04/07 16:27:19 The ... is a property of the function type, not a
gri 2011/04/08 02:41:32 I am not convinced. ... types behave likes slices
rsc 2011/04/08 03:25:44 Right. These are arguments for making it a proper
gri 2011/04/08 04:08:59 ah yes. the assignment property makes it obvious.
46 Elt Type
47 }
48
49
50 // A Struct represents a struct type struct{...}.
51 type Struct struct {
52 ImplementsType
53 Fields *ast.Scope // always present
rsc 2011/04/07 16:27:19 I'm surprised to see the ast mixed in here. I thin
gri 2011/04/08 02:41:32 It's a placeholder. Removed for now.
54 // TODO(gri) need to remember order of fields for
55 // struct type comparisons.
56 }
57
58
59 // A Pointer represents a pointer type *Base.
60 type Pointer struct {
61 ImplementsType
62 Base Type
rsc 2011/04/07 16:27:19 can this be Elt? Reflect uses the same name for a
gri 2011/04/08 02:41:32 It's really not an element. It's base type in the
rsc 2011/04/08 03:25:44 No, just a would be nice. Not a big deal.
63 }
64
65
66 // A Func represents a function type func(...) (...).
67 type Func struct {
68 ImplementsType
69 Params *ast.Scope // always present
rsc 2011/04/07 16:27:19 This is even more surprising as a scope, since the
gri 2011/04/08 02:41:32 There's a TODO below. This was a placeholder. remo
70 // TODO(gri) need to remember parameter order,
71 // number of results, receiver, etc.
72 }
73
74
75 // An Interface represents an interface type interface{...}.
76 type Interface struct {
77 ImplementsType
78 Methods *ast.Scope // always present
rsc 2011/04/07 16:27:19 Again.
gri 2011/04/08 02:41:32 Done.
79 }
80
81
82 // A Map represents a map type map[Key]Elt.
83 type Map struct {
84 ImplementsType
85 Key, Elt Type
86 }
87
88
89 // A Chan represents a channel type chan Elt, <-chan Elt, or chan<-Elt.
90 type Chan struct {
91 ImplementsType
92 Dir ast.ChanDir
93 Elt Type
94 }
95
96
97 // A Name represents a named type as declared in a type declaration.
98 type Name struct {
99 ImplementsType
100 Underlying Type // nil if not fully declared
101 Obj *ast.Object // corresponding declared object
102 Scope *ast.Scope // associated methods (and fields, if any); or ni l
rsc 2011/04/07 16:27:19 Again.
gri 2011/04/08 02:41:32 Done.
103 }
104
105
106 // Underlying returns the underlying type of a type.
107 func Underlying(typ Type) Type {
108 if typ, isName := typ.(*Name); isName {
109 return typ.Underlying
110 }
111 return typ
112 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b