]> Cypherpunks repositories - gostls13.git/commitdiff
go/*: various small fixes
authorRobert Griesemer <gri@golang.org>
Fri, 13 May 2011 03:14:58 +0000 (20:14 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 13 May 2011 03:14:58 +0000 (20:14 -0700)
parser:
- resolve embedded interface type names
ast:
- clarify some comments
- correctly unquote import paths

R=rsc
CC=golang-dev
https://golang.org/cl/4528060

src/pkg/go/ast/ast.go
src/pkg/go/ast/resolve.go
src/pkg/go/parser/parser.go

index 2fc1a60323dfdc0b9bb9e8683f63cfff04ad057c..d7221b33215b1e7cfe6817cedfce939dce551a22 100644 (file)
@@ -121,7 +121,7 @@ func (f *Field) End() token.Pos {
 // A FieldList represents a list of Fields, enclosed by parentheses or braces.
 type FieldList struct {
        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
 }
 
@@ -334,7 +334,7 @@ type (
        // A FuncType node represents a function type.
        FuncType struct {
                Func    token.Pos  // position of "func" keyword
-               Params  *FieldList // (incoming) parameters
+               Params  *FieldList // (incoming) parameters; or nil
                Results *FieldList // (outgoing) results; or nil
        }
 
@@ -946,8 +946,8 @@ func (f *File) End() token.Pos {
 //
 type Package struct {
        Name    string            // package name
-       Scope   *Scope            // package scope
-       Imports map[string]*Scope // map of import path -> package scope across all files
+       Scope   *Scope            // package scope across all files
+       Imports map[string]*Scope // map of import path -> package scope
        Files   map[string]*File  // Go source files by filename
 }
 
index fddc3baab86c61b91d33c08f67225da2eac90920..a2ff620daeb8ebd38f73662bae84a3433574c00d 100644 (file)
@@ -11,6 +11,7 @@ import (
        "go/scanner"
        "go/token"
        "os"
+       "strconv"
 )
 
 
@@ -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
 // remaining unresolved identifiers are reported as undeclared. If the files
 // 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.
 //
 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,
                fileScope := NewScope(pkgScope)
                for _, spec := range file.Imports {
                        // add import to global map of imports
-                       path := string(spec.Path.Value)
-                       path = path[1 : len(path)-1] // strip ""'s
+                       path, _ := strconv.Unquote(string(spec.Path.Value))
                        pkg := imports[path]
                        if pkg == nil {
                                if importer == nil {
@@ -161,8 +161,8 @@ func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer,
                if importErrors {
                        // don't use the universe scope without correct imports
                        // (objects in the universe may be shadowed by imports;
-                       // with missing imports identifiers might get resolved
-                       // wrongly)
+                       // with missing imports, identifiers might get resolved
+                       // incorrectly to universe objects)
                        pkgScope.Outer = nil
                }
                i := 0
index 6329cc918eb905f38650278c10694c598e8a9204..2bc550bac756526741b0052eeb8672e0a09a0c9c 100644 (file)
@@ -818,6 +818,7 @@ func (p *parser) parseMethodSpec(scope *ast.Scope) *ast.Field {
        } else {
                // embedded interface
                typ = x
+               p.resolve(typ)
        }
        p.expectSemi() // call before accessing p.linecomment