Skip to content

Commit bceddce

Browse files
committed
gotypes: minor fixes
Change-Id: Ie730f983c12a20c6c50e289650e230a05b1c782b Reviewed-on: https://go-review.googlesource.com/17972 Reviewed-by: Alan Donovan <[email protected]>
1 parent 637ffe0 commit bceddce

File tree

2 files changed

+46
-44
lines changed

2 files changed

+46
-44
lines changed

gotypes/README.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ instance---must have access to the `FileSet`.
222222

223223
Second, the program parses the input string.
224224
More realistic packages contain several source files, so the parsing
225-
step must be repeated for each one, or better still, done in parallel.
225+
step must be repeated for each one, or better, done in parallel.
226226
Third, it creates a `Config` that specifies type-checking options.
227227
Since the _hello, world_ program uses imports, we must indicate
228228
how to locate the imported packages.
@@ -304,11 +304,11 @@ object-oriented programming.)
304304

305305

306306

307-
Objects are represented by the `Object` interface, shown below:
307+
Objects are represented by the `Object` interface:
308308

309309

310310
type Object interface {
311-
Name() string // package local object name
311+
Name() string // package-local object name
312312
Exported() bool // reports whether the name starts with a capital letter
313313
Type() Type // object type
314314
Pos() token.Pos // position of object identifier in declaration
@@ -338,7 +338,7 @@ individual fields for the file name, line number, column, and byte
338338
offset, though usually we just call its `String` method:
339339

340340

341-
fmt.Fprintln(fset.Position(obj.Pos())) // "hello.go:10:6"
341+
fmt.Println(fset.Position(obj.Pos())) // "hello.go:10:6"
342342

343343

344344
Not all objects carry position information.
@@ -349,7 +349,7 @@ imported from such a file returns zero, also known as
349349

350350

351351

352-
There are eight kinds of objects in the Go type checker.
352+
There are eight kinds of object in the Go type checker.
353353
Most familiar are the kinds that can be declared at package level:
354354
constants, variables, functions, and types.
355355
Less familiar are statement labels, imported package names
@@ -388,6 +388,7 @@ which the object was declared; we'll come back to this in
388388
[Scopes](#scopes).
389389
Fields and methods are not found in the lexical environment, so
390390
their objects have no `Parent`.
391+
<!-- TODO check this -->
391392

392393

393394

@@ -702,8 +703,8 @@ The structure of the lexical environment thus forms a tree, with the
702703
universe block at the root, the package blocks beneath it, the file
703704
blocks beneath them, and then any number of local blocks beneath the
704705
files.
705-
The following methods of `Scope` make this tree structure
706-
accessible and navigable:
706+
We can access and navigate this tree structure with the following
707+
methods of `Scope`:
707708

708709

709710
func (s *Scope) Parent() *Scope
@@ -768,7 +769,7 @@ before or after that point.
768769

769770

770771
`Pos` and `End` report the `Scope`'s start and end
771-
position which, for explicit blocks, are coincident with its curly
772+
position which, for explicit blocks, coincide with its curly
772773
braces.
773774
`Contains` is a convenience method that reports whether a
774775
position lies in this interval.
@@ -898,6 +899,7 @@ each level of the tree of lexical blocks.
898899
PkgName ✔
899900
Label ✔
900901

902+
901903
# Initialization Order
902904

903905

@@ -951,7 +953,8 @@ Across packages, dependencies must be initialized first, although the
951953
order among them is not specified.
952954
That is, any topological order of the import graph will do.
953955
The `(*Package).Imports` method returns the set of direct
954-
dependencies of a package, in an unspecified order.
956+
dependencies of a package.
957+
>>>>>>> 637ffe0981073879a95f848fd9528efe9231bed9
955958
956959

957960
# Types
@@ -1066,7 +1069,7 @@ for expressions containing errors, or for objects without types, like
10661069
The `Name` method returns the name of the type, such as
10671070
`"float64"`, and the `Info` method returns a bitfield that
10681071
encodes information about the type, such as whether it is signed or
1069-
unsigned, integer or floating point, real or complex.
1072+
unsigned, integer or floating point, or real or complex.
10701073

10711074

10721075

@@ -1135,6 +1138,7 @@ ordered list of field tags.
11351138
Each field is a `Var` object whose `IsField` method returns true.
11361139
Field objects have no `Parent` scope, because they are
11371140
resolved through selections, not through the lexical environment.
1141+
<!-- TODO check this -->
11381142

11391143

11401144

@@ -1172,7 +1176,7 @@ and to `U`, and short of inspecting source positions or walking
11721176
the AST---neither of which is possible for objects loaded from compiler
11731177
export data---it is not possible to ascertain that `x` was declared as
11741178
part of `T`.
1175-
The type checker computes the exact same data structures given this input:
1179+
The type checker builds the exact same data structures given this input:
11761180

11771181

11781182
type T U
@@ -1264,7 +1268,7 @@ These types are recorded during type checking for later use
12641268
A type declaration creates a `TypeName` object, and the type of
12651269
that object is a `Named`.
12661270
These two entities, an object and a type, are distinct but closely
1267-
related, and they exist in one-to-one correpondence.
1271+
related, and they exist in one-to-one correspondence.
12681272

12691273

12701274
type Named struct{ ... }
@@ -1405,15 +1409,15 @@ of the `Info` struct, namely `Types`:
14051409
}
14061410

14071411

1408-
No entry is recorded for identifiers since the `Defs` and
1412+
No entries are recorded for identifiers since the `Defs` and
14091413
`Uses` maps provide more information about them.
1410-
Also, no entry is recorded for pseudo-expressions like
1414+
Also, no entries are recorded for pseudo-expressions like
14111415
`*ast.KeyValuePair` or `*ast.Ellipsis`.
14121416

14131417

14141418

14151419
The value of the `Types` map is a `TypeAndValue`, which
1416-
(unsurprisingly) holds the `Type` and value of the expression, and in
1420+
(unsurprisingly) holds the type and value of the expression, and in
14171421
addition, its _mode_.
14181422
The mode is opaque, but has predicates to answer questions such as:
14191423
Does this expression denote a value or a type? Does this value have an
@@ -1437,7 +1441,7 @@ satisfy each predicate.
14371441
func (TypeAndValue) IsNil() bool // e.g. "nil"
14381442
func (TypeAndValue) Addressable() bool // e.g. "a[i]" but not "f()", "m[key]"
14391443
func (TypeAndValue) Assignable() bool // e.g. "a[i]", "m[key]"
1440-
func (TypeAndValue) HasOk() bool // e.g. "&lt;-ch", "m[key]"
1444+
func (TypeAndValue) HasOk() bool // e.g. "<-ch", "m[key]"
14411445

14421446

14431447
The statement below inspects every expression within the AST of a single
@@ -1707,12 +1711,9 @@ and `Indirect`.
17071711

17081712
The `addressable` flag should be set if the receiver is a
17091713
_variable_ of type `T`, since in a method selection on a
1710-
variable, an implicit address-of operation (`&amp;`) may occur.
1714+
variable, an implicit address-of operation (`&`) may occur.
17111715
The flag indicates whether the methods of type `*T` should be
17121716
considered during the lookup.
1713-
1714-
1715-
17161717
(You may wonder why this parameter is necessary. Couldn't clients
17171718
instead call `LookupFieldOrMethod` on the pointer type `*T`
17181719
if the receiver is a `T` variable? The answer is that if
@@ -1826,7 +1827,7 @@ Clients can request the method set of a type `T` by calling
18261827
func (s *MethodSet) Lookup(pkg *Package, name string) *Selection
18271828

18281829

1829-
The `Len` and `At` methods access a a list of
1830+
The `Len` and `At` methods access a list of
18301831
`Selections`, all of kind `MethodVal`, ordered by `Id`.
18311832
The `Lookup` function allows lookup of a single method by
18321833
name (and package path, as explained in the previous section).
@@ -2087,7 +2088,7 @@ and for constructing new values:
20872088

20882089

20892090
All numeric `Value`s, whether integer or floating-point, signed or
2090-
unsigned, or real or complex, are represented more precisely than the
2091+
unsigned, or real or complex, are represented more precisely than
20912092
ordinary Go types like `int64` and `float64`.
20922093
Internally, the `go/constant` package uses multi-precision data types
20932094
like `Int`, `Rat`, and `Float` from the `math/big` package so that

gotypes/go-types.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ instance---must have access to the `FileSet`.
148148

149149
Second, the program parses the input string.
150150
More realistic packages contain several source files, so the parsing
151-
step must be repeated for each one, or better still, done in parallel.
151+
step must be repeated for each one, or better, done in parallel.
152152
Third, it creates a `Config` that specifies type-checking options.
153153
Since the _hello, world_ program uses imports, we must indicate
154154
how to locate the imported packages.
@@ -221,11 +221,11 @@ object-oriented programming.)
221221

222222

223223

224-
Objects are represented by the `Object` interface, shown below:
224+
Objects are represented by the `Object` interface:
225225

226226

227227
type Object interface {
228-
Name() string // package local object name
228+
Name() string // package-local object name
229229
Exported() bool // reports whether the name starts with a capital letter
230230
Type() Type // object type
231231
Pos() token.Pos // position of object identifier in declaration
@@ -255,7 +255,7 @@ individual fields for the file name, line number, column, and byte
255255
offset, though usually we just call its `String` method:
256256

257257

258-
fmt.Fprintln(fset.Position(obj.Pos())) // "hello.go:10:6"
258+
fmt.Println(fset.Position(obj.Pos())) // "hello.go:10:6"
259259

260260

261261
Not all objects carry position information.
@@ -266,7 +266,7 @@ imported from such a file returns zero, also known as
266266

267267

268268

269-
There are eight kinds of objects in the Go type checker.
269+
There are eight kinds of object in the Go type checker.
270270
Most familiar are the kinds that can be declared at package level:
271271
constants, variables, functions, and types.
272272
Less familiar are statement labels, imported package names
@@ -305,6 +305,7 @@ which the object was declared; we'll come back to this in
305305
[Scopes](#scopes).
306306
Fields and methods are not found in the lexical environment, so
307307
their objects have no `Parent`.
308+
<!-- TODO check this -->
308309

309310

310311

@@ -578,8 +579,8 @@ The structure of the lexical environment thus forms a tree, with the
578579
universe block at the root, the package blocks beneath it, the file
579580
blocks beneath them, and then any number of local blocks beneath the
580581
files.
581-
The following methods of `Scope` make this tree structure
582-
accessible and navigable:
582+
We can access and navigate this tree structure with the following
583+
methods of `Scope`:
583584

584585

585586
func (s *Scope) Parent() *Scope
@@ -644,7 +645,7 @@ before or after that point.
644645

645646

646647
`Pos` and `End` report the `Scope`'s start and end
647-
position which, for explicit blocks, are coincident with its curly
648+
position which, for explicit blocks, coincide with its curly
648649
braces.
649650
`Contains` is a convenience method that reports whether a
650651
position lies in this interval.
@@ -717,6 +718,7 @@ each level of the tree of lexical blocks.
717718
PkgName ✔
718719
Label ✔
719720

721+
720722
# Initialization Order
721723

722724

@@ -770,7 +772,8 @@ Across packages, dependencies must be initialized first, although the
770772
order among them is not specified.
771773
That is, any topological order of the import graph will do.
772774
The `(*Package).Imports` method returns the set of direct
773-
dependencies of a package, in an unspecified order.
775+
dependencies of a package.
776+
>>>>>>> 637ffe0981073879a95f848fd9528efe9231bed9
774777
775778

776779
# Types
@@ -885,7 +888,7 @@ for expressions containing errors, or for objects without types, like
885888
The `Name` method returns the name of the type, such as
886889
`"float64"`, and the `Info` method returns a bitfield that
887890
encodes information about the type, such as whether it is signed or
888-
unsigned, integer or floating point, real or complex.
891+
unsigned, integer or floating point, or real or complex.
889892

890893

891894

@@ -954,6 +957,7 @@ ordered list of field tags.
954957
Each field is a `Var` object whose `IsField` method returns true.
955958
Field objects have no `Parent` scope, because they are
956959
resolved through selections, not through the lexical environment.
960+
<!-- TODO check this -->
957961

958962

959963

@@ -991,7 +995,7 @@ and to `U`, and short of inspecting source positions or walking
991995
the AST---neither of which is possible for objects loaded from compiler
992996
export data---it is not possible to ascertain that `x` was declared as
993997
part of `T`.
994-
The type checker computes the exact same data structures given this input:
998+
The type checker builds the exact same data structures given this input:
995999

9961000

9971001
type T U
@@ -1083,7 +1087,7 @@ These types are recorded during type checking for later use
10831087
A type declaration creates a `TypeName` object, and the type of
10841088
that object is a `Named`.
10851089
These two entities, an object and a type, are distinct but closely
1086-
related, and they exist in one-to-one correpondence.
1090+
related, and they exist in one-to-one correspondence.
10871091

10881092

10891093
type Named struct{ ... }
@@ -1224,15 +1228,15 @@ of the `Info` struct, namely `Types`:
12241228
}
12251229

12261230

1227-
No entry is recorded for identifiers since the `Defs` and
1231+
No entries are recorded for identifiers since the `Defs` and
12281232
`Uses` maps provide more information about them.
1229-
Also, no entry is recorded for pseudo-expressions like
1233+
Also, no entries are recorded for pseudo-expressions like
12301234
`*ast.KeyValuePair` or `*ast.Ellipsis`.
12311235

12321236

12331237

12341238
The value of the `Types` map is a `TypeAndValue`, which
1235-
(unsurprisingly) holds the `Type` and value of the expression, and in
1239+
(unsurprisingly) holds the type and value of the expression, and in
12361240
addition, its _mode_.
12371241
The mode is opaque, but has predicates to answer questions such as:
12381242
Does this expression denote a value or a type? Does this value have an
@@ -1256,7 +1260,7 @@ satisfy each predicate.
12561260
func (TypeAndValue) IsNil() bool // e.g. "nil"
12571261
func (TypeAndValue) Addressable() bool // e.g. "a[i]" but not "f()", "m[key]"
12581262
func (TypeAndValue) Assignable() bool // e.g. "a[i]", "m[key]"
1259-
func (TypeAndValue) HasOk() bool // e.g. "&lt;-ch", "m[key]"
1263+
func (TypeAndValue) HasOk() bool // e.g. "<-ch", "m[key]"
12601264

12611265

12621266
The statement below inspects every expression within the AST of a single
@@ -1408,12 +1412,9 @@ and `Indirect`.
14081412

14091413
The `addressable` flag should be set if the receiver is a
14101414
_variable_ of type `T`, since in a method selection on a
1411-
variable, an implicit address-of operation (`&amp;`) may occur.
1415+
variable, an implicit address-of operation (`&`) may occur.
14121416
The flag indicates whether the methods of type `*T` should be
14131417
considered during the lookup.
1414-
1415-
1416-
14171418
(You may wonder why this parameter is necessary. Couldn't clients
14181419
instead call `LookupFieldOrMethod` on the pointer type `*T`
14191420
if the receiver is a `T` variable? The answer is that if
@@ -1527,7 +1528,7 @@ Clients can request the method set of a type `T` by calling
15271528
func (s *MethodSet) Lookup(pkg *Package, name string) *Selection
15281529

15291530

1530-
The `Len` and `At` methods access a a list of
1531+
The `Len` and `At` methods access a list of
15311532
`Selections`, all of kind `MethodVal`, ordered by `Id`.
15321533
The `Lookup` function allows lookup of a single method by
15331534
name (and package path, as explained in the previous section).
@@ -1687,7 +1688,7 @@ and for constructing new values:
16871688

16881689

16891690
All numeric `Value`s, whether integer or floating-point, signed or
1690-
unsigned, or real or complex, are represented more precisely than the
1691+
unsigned, or real or complex, are represented more precisely than
16911692
ordinary Go types like `int64` and `float64`.
16921693
Internally, the `go/constant` package uses multi-precision data types
16931694
like `Int`, `Rat`, and `Float` from the `math/big` package so that

0 commit comments

Comments
 (0)