Commit 71630337 authored by Robert Griesemer's avatar Robert Griesemer

go/*: various small fixes

parser:
- resolve embedded interface type names
ast:
- clarify some comments
- correctly unquote import paths

R=rsc
CC=golang-dev
https://golang.org/cl/4528060
parent 71102ad2
...@@ -121,7 +121,7 @@ func (f *Field) End() token.Pos { ...@@ -121,7 +121,7 @@ func (f *Field) End() token.Pos {
// A FieldList represents a list of Fields, enclosed by parentheses or braces. // A FieldList represents a list of Fields, enclosed by parentheses or braces.
type FieldList struct { type FieldList struct {
Opening token.Pos // position of opening parenthesis/brace, if any Opening token.Pos // position of opening parenthesis/brace, if any
List []*Field // field list List []*Field // field list; or nil
Closing token.Pos // position of closing parenthesis/brace, if any Closing token.Pos // position of closing parenthesis/brace, if any
} }
...@@ -334,7 +334,7 @@ type ( ...@@ -334,7 +334,7 @@ type (
// A FuncType node represents a function type. // A FuncType node represents a function type.
FuncType struct { FuncType struct {
Func token.Pos // position of "func" keyword Func token.Pos // position of "func" keyword
Params *FieldList // (incoming) parameters Params *FieldList // (incoming) parameters; or nil
Results *FieldList // (outgoing) results; or nil Results *FieldList // (outgoing) results; or nil
} }
...@@ -946,8 +946,8 @@ func (f *File) End() token.Pos { ...@@ -946,8 +946,8 @@ func (f *File) End() token.Pos {
// //
type Package struct { type Package struct {
Name string // package name Name string // package name
Scope *Scope // package scope Scope *Scope // package scope across all files
Imports map[string]*Scope // map of import path -> package scope across all files Imports map[string]*Scope // map of import path -> package scope
Files map[string]*File // Go source files by filename Files map[string]*File // Go source files by filename
} }
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"go/scanner" "go/scanner"
"go/token" "go/token"
"os" "os"
"strconv"
) )
...@@ -70,7 +71,7 @@ type Importer func(path string) (name string, scope *Scope, err os.Error) ...@@ -70,7 +71,7 @@ type Importer func(path string) (name string, scope *Scope, err os.Error)
// used to resolve identifiers not declared in any of the package files. Any // used to resolve identifiers not declared in any of the package files. Any
// remaining unresolved identifiers are reported as undeclared. If the files // remaining unresolved identifiers are reported as undeclared. If the files
// belong to different packages, one package name is selected and files with // belong to different packages, one package name is selected and files with
// different package name are reported and then ignored. // different package names are reported and then ignored.
// The result is a package node and a scanner.ErrorList if there were errors. // The result is a package node and a scanner.ErrorList if there were errors.
// //
func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, universe *Scope) (*Package, os.Error) { func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, universe *Scope) (*Package, os.Error) {
...@@ -118,8 +119,7 @@ func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, ...@@ -118,8 +119,7 @@ func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer,
fileScope := NewScope(pkgScope) fileScope := NewScope(pkgScope)
for _, spec := range file.Imports { for _, spec := range file.Imports {
// add import to global map of imports // add import to global map of imports
path := string(spec.Path.Value) path, _ := strconv.Unquote(string(spec.Path.Value))
path = path[1 : len(path)-1] // strip ""'s
pkg := imports[path] pkg := imports[path]
if pkg == nil { if pkg == nil {
if importer == nil { if importer == nil {
...@@ -161,8 +161,8 @@ func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, ...@@ -161,8 +161,8 @@ func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer,
if importErrors { if importErrors {
// don't use the universe scope without correct imports // don't use the universe scope without correct imports
// (objects in the universe may be shadowed by imports; // (objects in the universe may be shadowed by imports;
// with missing imports identifiers might get resolved // with missing imports, identifiers might get resolved
// wrongly) // incorrectly to universe objects)
pkgScope.Outer = nil pkgScope.Outer = nil
} }
i := 0 i := 0
......
...@@ -818,6 +818,7 @@ func (p *parser) parseMethodSpec(scope *ast.Scope) *ast.Field { ...@@ -818,6 +818,7 @@ func (p *parser) parseMethodSpec(scope *ast.Scope) *ast.Field {
} else { } else {
// embedded interface // embedded interface
typ = x typ = x
p.resolve(typ)
} }
p.expectSemi() // call before accessing p.linecomment p.expectSemi() // call before accessing p.linecomment
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment