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
1baffa7d
Commit
1baffa7d
authored
Apr 07, 2011
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gotype: use go/types GcImporter
R=rsc CC=golang-dev
https://golang.org/cl/4358043
parent
a87382e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
78 deletions
+4
-78
src/cmd/gotype/gotype.go
src/cmd/gotype/gotype.go
+2
-68
src/cmd/gotype/gotype_test.go
src/cmd/gotype/gotype_test.go
+2
-10
No files found.
src/cmd/gotype/gotype.go
View file @
1baffa7d
...
...
@@ -11,6 +11,7 @@ import (
"go/parser"
"go/scanner"
"go/token"
"go/types"
"io/ioutil"
"os"
"path/filepath"
...
...
@@ -170,13 +171,9 @@ func processFiles(filenames []string, allFiles bool) {
}
// TODO(gri) Replace this with a fully functioning importer.
// For now a dummy importer is set up by gotype_test.go.
var
importer
ast
.
Importer
func
processPackage
(
fset
*
token
.
FileSet
,
files
map
[
string
]
*
ast
.
File
)
{
// make a package (resolve all identifiers)
pkg
,
err
:=
ast
.
NewPackage
(
fset
,
files
,
importer
,
u
niverse
)
pkg
,
err
:=
ast
.
NewPackage
(
fset
,
files
,
types
.
GcImporter
,
types
.
U
niverse
)
if
err
!=
nil
{
report
(
err
)
return
...
...
@@ -199,66 +196,3 @@ func main() {
os
.
Exit
(
exitCode
)
}
// TODO(gri) Move universe and its initialization in to the right package.
var
universe
*
ast
.
Scope
func
define
(
kind
ast
.
ObjKind
,
names
...
string
)
{
for
_
,
name
:=
range
names
{
obj
:=
ast
.
NewObj
(
kind
,
name
)
if
universe
.
Insert
(
obj
)
!=
nil
{
panic
(
"gotype internal error: incorrect universe scope"
)
}
}
}
func
init
()
{
universe
=
ast
.
NewScope
(
nil
)
define
(
ast
.
Typ
,
"bool"
,
"byte"
,
"complex64"
,
"complex128"
,
"float32"
,
"float64"
,
"int8"
,
"int16"
,
"int32"
,
"int64"
,
"string"
,
"uint8"
,
"uint16"
,
"uint32"
,
"uint64"
,
"int"
,
"uint"
,
"uintptr"
,
)
define
(
ast
.
Con
,
"true"
,
"false"
,
"iota"
,
"nil"
,
)
define
(
ast
.
Fun
,
"append"
,
"cap"
,
"close"
,
"complex"
,
"copy"
,
"imag"
,
"len"
,
"make"
,
"new"
,
"panic"
,
"print"
,
"println"
,
"real"
,
"recover"
,
)
}
src/cmd/gotype/gotype_test.go
View file @
1baffa7d
...
...
@@ -5,26 +5,16 @@
package
main
import
(
"go/ast"
"os"
"path/filepath"
"runtime"
"path"
"testing"
)
func
testImporter
(
importPath
string
)
(
string
,
*
ast
.
Scope
,
os
.
Error
)
{
_
,
pkgName
:=
path
.
Split
(
importPath
)
// filename is package name for std library
return
pkgName
,
ast
.
NewScope
(
nil
),
nil
}
func
runTest
(
t
*
testing
.
T
,
path
,
pkg
string
)
{
exitCode
=
0
*
pkgName
=
pkg
*
recursive
=
false
importer
=
testImporter
if
pkg
==
""
{
processFiles
([]
string
{
path
},
true
)
...
...
@@ -47,9 +37,11 @@ var tests = []struct {
// directories
{
filepath
.
Join
(
runtime
.
GOROOT
(),
"src/pkg/go/ast"
),
"ast"
},
{
filepath
.
Join
(
runtime
.
GOROOT
(),
"src/pkg/go/doc"
),
"doc"
},
{
filepath
.
Join
(
runtime
.
GOROOT
(),
"src/pkg/go/token"
),
"scanner"
},
{
filepath
.
Join
(
runtime
.
GOROOT
(),
"src/pkg/go/scanner"
),
"scanner"
},
{
filepath
.
Join
(
runtime
.
GOROOT
(),
"src/pkg/go/parser"
),
"parser"
},
{
filepath
.
Join
(
runtime
.
GOROOT
(),
"src/pkg/go/types"
),
"types"
},
}
...
...
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