Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
098e9417
Commit
098e9417
authored
Oct 28, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/typechecker: use append
R=rsc CC=golang-dev
https://golang.org/cl/2736044
parent
6062515a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
23 deletions
+11
-23
src/pkg/go/typechecker/typechecker.go
src/pkg/go/typechecker/typechecker.go
+7
-10
src/pkg/go/typechecker/typechecker_test.go
src/pkg/go/typechecker/typechecker_test.go
+4
-13
No files found.
src/pkg/go/typechecker/typechecker.go
View file @
098e9417
...
...
@@ -9,7 +9,6 @@
package
typechecker
import
(
"container/vector"
"fmt"
"go/ast"
"go/token"
...
...
@@ -122,21 +121,20 @@ func (tc *typechecker) checkPackage(pkg *ast.Package) {
// TODO(gri) there's no file scope at the moment since we ignore imports
// phase 1: declare all global objects; also collect all function and method declarations
var
funcs
vector
.
Vector
var
funcs
[]
*
ast
.
FuncDecl
for
_
,
file
:=
range
pkg
.
Files
{
for
_
,
decl
:=
range
file
.
Decls
{
tc
.
declGlobal
(
decl
)
if
f
,
isFunc
:=
decl
.
(
*
ast
.
FuncDecl
);
isFunc
{
funcs
.
Push
(
f
)
funcs
=
append
(
funcs
,
f
)
}
}
}
// phase 2: bind methods to their receiver base types
for
_
,
decl
:=
range
funcs
{
d
:=
decl
.
(
*
ast
.
FuncDecl
)
if
d
.
Recv
!=
nil
{
tc
.
bindMethod
(
d
)
for
_
,
m
:=
range
funcs
{
if
m
.
Recv
!=
nil
{
tc
.
bindMethod
(
m
)
}
}
...
...
@@ -149,9 +147,8 @@ func (tc *typechecker) checkPackage(pkg *ast.Package) {
assert
(
len
(
tc
.
cyclemap
)
==
0
)
// 4: sequentially typecheck function and method bodies
for
_
,
decl
:=
range
funcs
{
d
:=
decl
.
(
*
ast
.
FuncDecl
)
tc
.
checkBlock
(
d
.
Body
.
List
,
d
.
Name
.
Obj
.
Type
)
for
_
,
f
:=
range
funcs
{
tc
.
checkBlock
(
f
.
Body
.
List
,
f
.
Name
.
Obj
.
Type
)
}
pkg
.
Scope
=
tc
.
topScope
...
...
src/pkg/go/typechecker/typechecker_test.go
View file @
098e9417
...
...
@@ -27,7 +27,6 @@
package
typechecker
import
(
"container/vector"
"flag"
"fmt"
"go/ast"
...
...
@@ -58,9 +57,7 @@ var errRx = regexp.MustCompile(`^/\* *ERROR *"([^"]*)" *\*/$`)
// expectedErrors collects the regular expressions of ERROR comments
// found in the package files of pkg and returns them in sorted order
// (by filename and position).
func
expectedErrors
(
t
*
testing
.
T
,
pkg
*
ast
.
Package
)
scanner
.
ErrorList
{
var
list
vector
.
Vector
func
expectedErrors
(
t
*
testing
.
T
,
pkg
*
ast
.
Package
)
(
list
scanner
.
ErrorList
)
{
// scan all package files
for
filename
:=
range
pkg
.
Files
{
src
,
err
:=
ioutil
.
ReadFile
(
filename
)
...
...
@@ -80,21 +77,15 @@ func expectedErrors(t *testing.T, pkg *ast.Package) scanner.ErrorList {
case
token
.
COMMENT
:
s
:=
errRx
.
FindSubmatch
(
lit
)
if
len
(
s
)
==
2
{
list
.
Push
(
&
scanner
.
Error
{
prev
,
string
(
s
[
1
])})
list
=
append
(
list
,
&
scanner
.
Error
{
prev
,
string
(
s
[
1
])})
}
default
:
prev
=
pos
}
}
}
// convert list
errs
:=
make
(
scanner
.
ErrorList
,
len
(
list
))
for
i
,
e
:=
range
list
{
errs
[
i
]
=
e
.
(
*
scanner
.
Error
)
}
sort
.
Sort
(
errs
)
// multiple files may not be sorted
return
errs
sort
.
Sort
(
list
)
// multiple files may not be sorted
return
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment