diff --git a/go/loader/pkginfo.go b/go/loader/pkginfo.go index fbd8ada6..bbd3b26e 100644 --- a/go/loader/pkginfo.go +++ b/go/loader/pkginfo.go @@ -24,10 +24,8 @@ type PackageInfo struct { Files []*ast.File // abstract syntax for the package's files TypeError error // non-nil if the package had type errors types.Info // type-checker deductions. - - checker interface { - Files(files []*ast.File) error - } // transient type-checker state + *types.Checker + checker *types.Checker // transient type-checker state } func (info *PackageInfo) String() string { diff --git a/go/types/assignments.go b/go/types/assignments.go index d79e418b..743918e8 100644 --- a/go/types/assignments.go +++ b/go/types/assignments.go @@ -21,7 +21,7 @@ import ( // // TODO(gri) Should find a better way to handle in-band errors. // -func (check *checker) assignment(x *operand, T Type) bool { +func (check *Checker) assignment(x *operand, T Type) bool { switch x.mode { case invalid: return true // error reported before @@ -67,7 +67,7 @@ func (check *checker) assignment(x *operand, T Type) bool { return T == nil || x.assignableTo(check.conf, T) } -func (check *checker) initConst(lhs *Const, x *operand) { +func (check *Checker) initConst(lhs *Const, x *operand) { if x.mode == invalid || x.typ == Typ[Invalid] || lhs.typ == Typ[Invalid] { if lhs.typ == nil { lhs.typ = Typ[Invalid] @@ -102,7 +102,7 @@ func (check *checker) initConst(lhs *Const, x *operand) { } // If result is set, lhs is a function result parameter and x is a return result. -func (check *checker) initVar(lhs *Var, x *operand, result bool) Type { +func (check *Checker) initVar(lhs *Var, x *operand, result bool) Type { if x.mode == invalid || x.typ == Typ[Invalid] || lhs.typ == Typ[Invalid] { if lhs.typ == nil { lhs.typ = Typ[Invalid] @@ -140,7 +140,7 @@ func (check *checker) initVar(lhs *Var, x *operand, result bool) Type { return x.typ } -func (check *checker) assignVar(lhs ast.Expr, x *operand) Type { +func (check *Checker) assignVar(lhs ast.Expr, x *operand) Type { if x.mode == invalid || x.typ == Typ[Invalid] { return nil } @@ -206,7 +206,7 @@ func (check *checker) assignVar(lhs ast.Expr, x *operand) Type { // If returnPos is valid, initVars is called to type-check the assignment of // return expressions, and returnPos is the position of the return statement. -func (check *checker) initVars(lhs []*Var, rhs []ast.Expr, returnPos token.Pos) { +func (check *Checker) initVars(lhs []*Var, rhs []ast.Expr, returnPos token.Pos) { l := len(lhs) get, r, commaOk := unpack(func(x *operand, i int) { check.expr(x, rhs[i]) }, len(rhs), l == 2 && !returnPos.IsValid()) if l != r { @@ -242,7 +242,7 @@ func (check *checker) initVars(lhs []*Var, rhs []ast.Expr, returnPos token.Pos) } } -func (check *checker) assignVars(lhs, rhs []ast.Expr) { +func (check *Checker) assignVars(lhs, rhs []ast.Expr) { l := len(lhs) get, r, commaOk := unpack(func(x *operand, i int) { check.expr(x, rhs[i]) }, len(rhs), l == 2) if l != r { @@ -268,7 +268,7 @@ func (check *checker) assignVars(lhs, rhs []ast.Expr) { } } -func (check *checker) shortVarDecl(pos token.Pos, lhs, rhs []ast.Expr) { +func (check *Checker) shortVarDecl(pos token.Pos, lhs, rhs []ast.Expr) { scope := check.scope // collect lhs variables diff --git a/go/types/builtins.go b/go/types/builtins.go index 7fe8353c..aca43225 100644 --- a/go/types/builtins.go +++ b/go/types/builtins.go @@ -18,7 +18,7 @@ import ( // but x.expr is not set. If the call is invalid, the result is // false, and *x is undefined. // -func (check *checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ bool) { +func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ bool) { // append is the only built-in that permits the use of ... for the last argument bin := predeclaredFuncs[id] if call.Ellipsis.IsValid() && id != _Append { @@ -608,7 +608,7 @@ func unparen(x ast.Expr) ast.Expr { return x } -func (check *checker) complexArg(x *operand) bool { +func (check *Checker) complexArg(x *operand) bool { t, _ := x.typ.Underlying().(*Basic) if t != nil && (t.info&IsFloat != 0 || t.kind == UntypedInt || t.kind == UntypedRune) { return true diff --git a/go/types/call.go b/go/types/call.go index b044295e..b8ee6d24 100644 --- a/go/types/call.go +++ b/go/types/call.go @@ -11,7 +11,7 @@ import ( "go/token" ) -func (check *checker) call(x *operand, e *ast.CallExpr) exprKind { +func (check *Checker) call(x *operand, e *ast.CallExpr) exprKind { check.exprOrType(x, e.Fun) switch x.mode { @@ -85,7 +85,7 @@ func (check *checker) call(x *operand, e *ast.CallExpr) exprKind { // use type-checks each argument. // Useful to make sure expressions are evaluated // (and variables are "used") in the presence of other errors. -func (check *checker) use(arg ...ast.Expr) { +func (check *Checker) use(arg ...ast.Expr) { var x operand for _, e := range arg { check.rawExpr(&x, e, nil) @@ -165,7 +165,7 @@ func unpack(get getter, n int, allowCommaOk bool) (getter, int, bool) { // arguments checks argument passing for the call with the given signature. // The arg function provides the operand for the i'th argument. -func (check *checker) arguments(x *operand, call *ast.CallExpr, sig *Signature, arg getter, n int) { +func (check *Checker) arguments(x *operand, call *ast.CallExpr, sig *Signature, arg getter, n int) { passSlice := false if call.Ellipsis.IsValid() { // last argument is of the form x... @@ -199,7 +199,7 @@ func (check *checker) arguments(x *operand, call *ast.CallExpr, sig *Signature, // argument checks passing of argument x to the i'th parameter of the given signature. // If passSlice is set, the argument is followed by ... in the call. -func (check *checker) argument(sig *Signature, i int, x *operand, passSlice bool) { +func (check *Checker) argument(sig *Signature, i int, x *operand, passSlice bool) { n := sig.params.Len() // determine parameter type @@ -239,7 +239,7 @@ func (check *checker) argument(sig *Signature, i int, x *operand, passSlice bool } } -func (check *checker) selector(x *operand, e *ast.SelectorExpr) { +func (check *Checker) selector(x *operand, e *ast.SelectorExpr) { // these must be declared before the "goto Error" statements var ( obj Object diff --git a/go/types/check.go b/go/types/check.go index bc85d08a..71bbfe79 100644 --- a/go/types/check.go +++ b/go/types/check.go @@ -45,9 +45,9 @@ type context struct { hasCallOrRecv bool // set if an expression contains a function call or channel receive operation } -// A checker maintains the state of the type checker. +// A Checker maintains the state of the type checker. // It must be created with NewChecker. -type checker struct { +type Checker struct { // package information // (initialized by NewChecker, valid for the life-time of checker) conf *Config @@ -78,7 +78,7 @@ type checker struct { } // addDeclDep adds the dependency edge (check.decl -> to) if check.decl exists -func (check *checker) addDeclDep(to Object) { +func (check *Checker) addDeclDep(to Object) { from := check.decl if from == nil { return // not in a package-level init expression @@ -89,7 +89,7 @@ func (check *checker) addDeclDep(to Object) { from.addDep(to) } -func (check *checker) assocMethod(tname string, meth *Func) { +func (check *Checker) assocMethod(tname string, meth *Func) { m := check.methods if m == nil { m = make(map[string][]*Func) @@ -98,7 +98,7 @@ func (check *checker) assocMethod(tname string, meth *Func) { m[tname] = append(m[tname], meth) } -func (check *checker) rememberUntyped(e ast.Expr, lhs bool, typ *Basic, val exact.Value) { +func (check *Checker) rememberUntyped(e ast.Expr, lhs bool, typ *Basic, val exact.Value) { m := check.untyped if m == nil { m = make(map[ast.Expr]exprInfo) @@ -107,17 +107,17 @@ func (check *checker) rememberUntyped(e ast.Expr, lhs bool, typ *Basic, val exac m[e] = exprInfo{lhs, typ, val} } -func (check *checker) later(name string, decl *declInfo, sig *Signature, body *ast.BlockStmt) { +func (check *Checker) later(name string, decl *declInfo, sig *Signature, body *ast.BlockStmt) { check.funcs = append(check.funcs, funcInfo{name, decl, sig, body}) } -func (check *checker) delay(f func()) { +func (check *Checker) delay(f func()) { check.delayed = append(check.delayed, f) } // NewChecker returns a new Checker instance for a given package. -// Package files may be incrementally added via checker.Files. -func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *checker { +// Package files may be added incrementally via checker.Files. +func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Checker { // make sure we have a configuration if conf == nil { conf = new(Config) @@ -133,7 +133,7 @@ func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *ch info = new(Info) } - return &checker{ + return &Checker{ conf: conf, fset: fset, pkg: pkg, @@ -144,7 +144,7 @@ func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *ch // initFiles initializes the files-specific portion of checker. // The provided files must all belong to the same package. -func (check *checker) initFiles(files []*ast.File) { +func (check *Checker) initFiles(files []*ast.File) { // start with a clean slate (check.Files may be called multiple times) check.files = nil check.fileScopes = nil @@ -191,7 +191,7 @@ func (check *checker) initFiles(files []*ast.File) { // A bailout panic is used for early termination. type bailout struct{} -func (check *checker) handleBailout(err *error) { +func (check *Checker) handleBailout(err *error) { switch p := recover().(type) { case nil, bailout: // normal return or early exit @@ -203,7 +203,7 @@ func (check *checker) handleBailout(err *error) { } // Files checks the provided files as part of the checker's package. -func (check *checker) Files(files []*ast.File) (err error) { +func (check *Checker) Files(files []*ast.File) (err error) { defer check.handleBailout(&err) check.initFiles(files) @@ -229,7 +229,7 @@ func (check *checker) Files(files []*ast.File) (err error) { return } -func (check *checker) recordUntyped() { +func (check *Checker) recordUntyped() { if !debug && check.Types == nil { return // nothing to do } @@ -243,7 +243,7 @@ func (check *checker) recordUntyped() { } } -func (check *checker) recordTypeAndValue(x ast.Expr, typ Type, val exact.Value) { +func (check *Checker) recordTypeAndValue(x ast.Expr, typ Type, val exact.Value) { assert(x != nil && typ != nil) if val != nil { assert(isConstType(typ)) @@ -253,7 +253,7 @@ func (check *checker) recordTypeAndValue(x ast.Expr, typ Type, val exact.Value) } } -func (check *checker) recordBuiltinType(f ast.Expr, sig *Signature) { +func (check *Checker) recordBuiltinType(f ast.Expr, sig *Signature) { // f must be a (possibly parenthesized) identifier denoting a built-in // (built-ins in package unsafe always produce a constant result and // we don't record their signatures, so we don't see qualified idents @@ -271,7 +271,7 @@ func (check *checker) recordBuiltinType(f ast.Expr, sig *Signature) { } } -func (check *checker) recordCommaOkTypes(x ast.Expr, a [2]Type) { +func (check *Checker) recordCommaOkTypes(x ast.Expr, a [2]Type) { assert(x != nil) if a[0] == nil || a[1] == nil { return @@ -297,14 +297,14 @@ func (check *checker) recordCommaOkTypes(x ast.Expr, a [2]Type) { } } -func (check *checker) recordDef(id *ast.Ident, obj Object) { +func (check *Checker) recordDef(id *ast.Ident, obj Object) { assert(id != nil) if m := check.Defs; m != nil { m[id] = obj } } -func (check *checker) recordUse(id *ast.Ident, obj Object) { +func (check *Checker) recordUse(id *ast.Ident, obj Object) { assert(id != nil) assert(obj != nil) if m := check.Uses; m != nil { @@ -312,14 +312,14 @@ func (check *checker) recordUse(id *ast.Ident, obj Object) { } } -func (check *checker) recordImplicit(node ast.Node, obj Object) { +func (check *Checker) recordImplicit(node ast.Node, obj Object) { assert(node != nil && obj != nil) if m := check.Implicits; m != nil { m[node] = obj } } -func (check *checker) recordSelection(x *ast.SelectorExpr, kind SelectionKind, recv Type, obj Object, index []int, indirect bool) { +func (check *Checker) recordSelection(x *ast.SelectorExpr, kind SelectionKind, recv Type, obj Object, index []int, indirect bool) { assert(obj != nil && (recv == nil || len(index) > 0)) check.recordUse(x.Sel, obj) // TODO(gri) Should we also call recordTypeAndValue? @@ -328,7 +328,7 @@ func (check *checker) recordSelection(x *ast.SelectorExpr, kind SelectionKind, r } } -func (check *checker) recordScope(node ast.Node, scope *Scope) { +func (check *Checker) recordScope(node ast.Node, scope *Scope) { assert(node != nil && scope != nil) if m := check.Scopes; m != nil { m[node] = scope diff --git a/go/types/conversions.go b/go/types/conversions.go index 15fb0543..e9518876 100644 --- a/go/types/conversions.go +++ b/go/types/conversions.go @@ -10,7 +10,7 @@ import "code.google.com/p/go.tools/go/exact" // Conversion type-checks the conversion T(x). // The result is in x. -func (check *checker) conversion(x *operand, T Type) { +func (check *Checker) conversion(x *operand, T Type) { constArg := x.mode == constant var ok bool diff --git a/go/types/decl.go b/go/types/decl.go index 8ef003d4..623d35f6 100644 --- a/go/types/decl.go +++ b/go/types/decl.go @@ -11,7 +11,7 @@ import ( "code.google.com/p/go.tools/go/exact" ) -func (check *checker) reportAltDecl(obj Object) { +func (check *Checker) reportAltDecl(obj Object) { if pos := obj.Pos(); pos.IsValid() { // We use "other" rather than "previous" here because // the first declaration seen may not be textually @@ -20,7 +20,7 @@ func (check *checker) reportAltDecl(obj Object) { } } -func (check *checker) declare(scope *Scope, id *ast.Ident, obj Object) { +func (check *Checker) declare(scope *Scope, id *ast.Ident, obj Object) { // spec: "The blank identifier, represented by the underscore // character _, may be used in a declaration like any other // identifier but the declaration does not introduce a new @@ -39,7 +39,7 @@ func (check *checker) declare(scope *Scope, id *ast.Ident, obj Object) { // objDecl type-checks the declaration of obj in its respective (file) context. // See check.typ for the details on def and path. -func (check *checker) objDecl(obj Object, def *Named, path []*TypeName) { +func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) { if obj.Type() != nil { return // already checked - nothing to do } @@ -85,7 +85,7 @@ func (check *checker) objDecl(obj Object, def *Named, path []*TypeName) { } } -func (check *checker) constDecl(obj *Const, typ, init ast.Expr) { +func (check *Checker) constDecl(obj *Const, typ, init ast.Expr) { assert(obj.typ == nil) if obj.visited { @@ -118,7 +118,7 @@ func (check *checker) constDecl(obj *Const, typ, init ast.Expr) { check.initConst(obj, &x) } -func (check *checker) varDecl(obj *Var, lhs []*Var, typ, init ast.Expr) { +func (check *Checker) varDecl(obj *Var, lhs []*Var, typ, init ast.Expr) { assert(obj.typ == nil) if obj.visited { @@ -188,7 +188,7 @@ func (n *Named) setUnderlying(typ Type) { } } -func (check *checker) typeDecl(obj *TypeName, typ ast.Expr, def *Named, path []*TypeName) { +func (check *Checker) typeDecl(obj *TypeName, typ ast.Expr, def *Named, path []*TypeName) { assert(obj.typ == nil) // type declarations cannot use iota @@ -224,7 +224,7 @@ func (check *checker) typeDecl(obj *TypeName, typ ast.Expr, def *Named, path []* check.addMethodDecls(obj) } -func (check *checker) addMethodDecls(obj *TypeName) { +func (check *Checker) addMethodDecls(obj *TypeName) { // get associated methods methods := check.methods[obj.name] if len(methods) == 0 { @@ -280,7 +280,7 @@ func (check *checker) addMethodDecls(obj *TypeName) { } } -func (check *checker) funcDecl(obj *Func, decl *declInfo) { +func (check *Checker) funcDecl(obj *Func, decl *declInfo) { assert(obj.typ == nil) // func declarations cannot use iota @@ -302,7 +302,7 @@ func (check *checker) funcDecl(obj *Func, decl *declInfo) { } } -func (check *checker) declStmt(decl ast.Decl) { +func (check *Checker) declStmt(decl ast.Decl) { pkg := check.pkg switch d := decl.(type) { diff --git a/go/types/errors.go b/go/types/errors.go index 8795e590..0a9dd0e1 100644 --- a/go/types/errors.go +++ b/go/types/errors.go @@ -23,7 +23,7 @@ func unreachable() { panic("unreachable") } -func (check *checker) sprintf(format string, args ...interface{}) string { +func (check *Checker) sprintf(format string, args ...interface{}) string { for i, arg := range args { switch a := arg.(type) { case nil: @@ -46,7 +46,7 @@ func (check *checker) sprintf(format string, args ...interface{}) string { return fmt.Sprintf(format, args...) } -func (check *checker) trace(pos token.Pos, format string, args ...interface{}) { +func (check *Checker) trace(pos token.Pos, format string, args ...interface{}) { fmt.Printf("%s:\t%s%s\n", check.fset.Position(pos), strings.Repeat(". ", check.indent), @@ -55,11 +55,11 @@ func (check *checker) trace(pos token.Pos, format string, args ...interface{}) { } // dump is only needed for debugging -func (check *checker) dump(format string, args ...interface{}) { +func (check *Checker) dump(format string, args ...interface{}) { fmt.Println(check.sprintf(format, args...)) } -func (check *checker) err(pos token.Pos, msg string, soft bool) { +func (check *Checker) err(pos token.Pos, msg string, soft bool) { err := Error{check.fset, pos, msg, soft} if check.firstErr == nil { check.firstErr = err @@ -71,26 +71,26 @@ func (check *checker) err(pos token.Pos, msg string, soft bool) { f(err) } -func (check *checker) error(pos token.Pos, msg string) { +func (check *Checker) error(pos token.Pos, msg string) { check.err(pos, msg, false) } -func (check *checker) errorf(pos token.Pos, format string, args ...interface{}) { +func (check *Checker) errorf(pos token.Pos, format string, args ...interface{}) { check.err(pos, check.sprintf(format, args...), false) } -func (check *checker) softErrorf(pos token.Pos, format string, args ...interface{}) { +func (check *Checker) softErrorf(pos token.Pos, format string, args ...interface{}) { check.err(pos, check.sprintf(format, args...), true) } -func (check *checker) invalidAST(pos token.Pos, format string, args ...interface{}) { +func (check *Checker) invalidAST(pos token.Pos, format string, args ...interface{}) { check.errorf(pos, "invalid AST: "+format, args...) } -func (check *checker) invalidArg(pos token.Pos, format string, args ...interface{}) { +func (check *Checker) invalidArg(pos token.Pos, format string, args ...interface{}) { check.errorf(pos, "invalid argument: "+format, args...) } -func (check *checker) invalidOp(pos token.Pos, format string, args ...interface{}) { +func (check *Checker) invalidOp(pos token.Pos, format string, args ...interface{}) { check.errorf(pos, "invalid operation: "+format, args...) } diff --git a/go/types/expr.go b/go/types/expr.go index a971686a..be11a040 100644 --- a/go/types/expr.go +++ b/go/types/expr.go @@ -66,7 +66,7 @@ var unaryOpPredicates = opPredicates{ token.NOT: isBoolean, } -func (check *checker) op(m opPredicates, x *operand, op token.Token) bool { +func (check *Checker) op(m opPredicates, x *operand, op token.Token) bool { if pred := m[op]; pred != nil { if !pred(x.typ) { check.invalidOp(x.pos(), "operator %s not defined for %s", op, x) @@ -79,7 +79,7 @@ func (check *checker) op(m opPredicates, x *operand, op token.Token) bool { return true } -func (check *checker) unary(x *operand, op token.Token) { +func (check *Checker) unary(x *operand, op token.Token) { switch op { case token.AND: // spec: "As an exception to the addressability @@ -320,7 +320,7 @@ func representableConst(x exact.Value, conf *Config, as BasicKind, rounded *exac } // representable checks that a constant operand is representable in the given basic type. -func (check *checker) representable(x *operand, typ *Basic) { +func (check *Checker) representable(x *operand, typ *Basic) { assert(x.mode == constant) if !representableConst(x.val, check.conf, typ.kind, &x.val) { var msg string @@ -355,7 +355,7 @@ func (check *checker) representable(x *operand, typ *Basic) { // and if x is the (formerly untyped) lhs operand of a non-constant // shift, it must be an integer value. // -func (check *checker) updateExprType(x ast.Expr, typ Type, final bool) { +func (check *Checker) updateExprType(x ast.Expr, typ Type, final bool) { old, found := check.untyped[x] if !found { return // nothing to do @@ -455,7 +455,7 @@ func (check *checker) updateExprType(x ast.Expr, typ Type, final bool) { } // updateExprVal updates the value of x to val. -func (check *checker) updateExprVal(x ast.Expr, val exact.Value) { +func (check *Checker) updateExprVal(x ast.Expr, val exact.Value) { if info, ok := check.untyped[x]; ok { info.val = val check.untyped[x] = info @@ -463,7 +463,7 @@ func (check *checker) updateExprVal(x ast.Expr, val exact.Value) { } // convertUntyped attempts to set the type of an untyped value to the target type. -func (check *checker) convertUntyped(x *operand, target Type) { +func (check *Checker) convertUntyped(x *operand, target Type) { if x.mode == invalid || isTyped(x.typ) || target == Typ[Invalid] { return } @@ -563,7 +563,7 @@ Error: x.mode = invalid } -func (check *checker) comparison(x, y *operand, op token.Token) { +func (check *Checker) comparison(x, y *operand, op token.Token) { // spec: "In any comparison, the first operand must be assignable // to the type of the second operand, or vice versa." err := "" @@ -615,7 +615,7 @@ func (check *checker) comparison(x, y *operand, op token.Token) { x.typ = Typ[UntypedBool] } -func (check *checker) shift(x, y *operand, op token.Token) { +func (check *Checker) shift(x, y *operand, op token.Token) { untypedx := isUntyped(x.typ) // The lhs must be of integer type or be representable @@ -716,7 +716,7 @@ var binaryOpPredicates = opPredicates{ token.LOR: isBoolean, } -func (check *checker) binary(x *operand, lhs, rhs ast.Expr, op token.Token) { +func (check *Checker) binary(x *operand, lhs, rhs ast.Expr, op token.Token) { var y operand check.expr(x, lhs) @@ -794,7 +794,7 @@ func (check *checker) binary(x *operand, lhs, rhs ast.Expr, op token.Token) { // index checks an index expression for validity. // If max >= 0, it is the upper bound for index. // If index is valid and the result i >= 0, then i is the constant value of index. -func (check *checker) index(index ast.Expr, max int64) (i int64, valid bool) { +func (check *Checker) index(index ast.Expr, max int64) (i int64, valid bool) { var x operand check.expr(&x, index) if x.mode == invalid { @@ -836,7 +836,7 @@ func (check *checker) index(index ast.Expr, max int64) (i int64, valid bool) { // the literal length if known (length >= 0). It returns the length of the // literal (maximum index value + 1). // -func (check *checker) indexedElts(elts []ast.Expr, typ Type, length int64) int64 { +func (check *Checker) indexedElts(elts []ast.Expr, typ Type, length int64) int64 { visited := make(map[int64]bool, len(elts)) var index, max int64 for _, e := range elts { @@ -895,7 +895,7 @@ const ( // value or type. If an error occurred, x.mode is set to invalid. // If hint != nil, it is the type of a composite literal element. // -func (check *checker) rawExpr(x *operand, e ast.Expr, hint Type) exprKind { +func (check *Checker) rawExpr(x *operand, e ast.Expr, hint Type) exprKind { if trace { check.trace(e.Pos(), "%s", e) check.indent++ @@ -937,7 +937,7 @@ func (check *checker) rawExpr(x *operand, e ast.Expr, hint Type) exprKind { // exprInternal contains the core of type checking of expressions. // Must only be called by rawExpr. // -func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { +func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { // make sure x has a valid state in case of bailout // (was issue 5770) x.mode = invalid @@ -1404,7 +1404,7 @@ Error: } // typeAssertion checks that x.(T) is legal; xtyp must be the type of x. -func (check *checker) typeAssertion(pos token.Pos, x *operand, xtyp *Interface, T Type) { +func (check *Checker) typeAssertion(pos token.Pos, x *operand, xtyp *Interface, T Type) { method, wrongType := MissingMethod(T, xtyp, false) if method == nil { return @@ -1421,7 +1421,7 @@ func (check *checker) typeAssertion(pos token.Pos, x *operand, xtyp *Interface, // expr typechecks expression e and initializes x with the expression value. // If an error occurred, x.mode is set to invalid. // -func (check *checker) expr(x *operand, e ast.Expr) { +func (check *Checker) expr(x *operand, e ast.Expr) { check.rawExpr(x, e, nil) var msg string switch x.mode { @@ -1442,7 +1442,7 @@ func (check *checker) expr(x *operand, e ast.Expr) { // If an error occurred, x.mode is set to invalid. // If hint != nil, it is the type of a composite literal element. // -func (check *checker) exprWithHint(x *operand, e ast.Expr, hint Type) { +func (check *Checker) exprWithHint(x *operand, e ast.Expr, hint Type) { assert(hint != nil) check.rawExpr(x, e, hint) var msg string @@ -1463,7 +1463,7 @@ func (check *checker) exprWithHint(x *operand, e ast.Expr, hint Type) { // exprOrType typechecks expression or type e and initializes x with the expression value or type. // If an error occurred, x.mode is set to invalid. // -func (check *checker) exprOrType(x *operand, e ast.Expr) { +func (check *Checker) exprOrType(x *operand, e ast.Expr) { check.rawExpr(x, e, nil) if x.mode == novalue { check.errorf(x.pos(), "%s used as value or type", x) diff --git a/go/types/initorder.go b/go/types/initorder.go index fa731b34..da5f541e 100644 --- a/go/types/initorder.go +++ b/go/types/initorder.go @@ -10,7 +10,7 @@ import ( ) // initOrder computes the Info.InitOrder for package variables. -func (check *checker) initOrder() { +func (check *Checker) initOrder() { // compute the object dependency graph and // initialize a priority queue with the list // of graph nodes @@ -129,7 +129,7 @@ func valIndex(a []*objNode) int { } // reportCycle reports an error for the cycle starting at i. -func (check *checker) reportCycle(cycle []*objNode, i int) { +func (check *Checker) reportCycle(cycle []*objNode, i int) { obj := cycle[i].obj check.errorf(obj.Pos(), "initialization cycle for %s", obj.Name()) // print cycle diff --git a/go/types/labels.go b/go/types/labels.go index ee89993a..fe0319c8 100644 --- a/go/types/labels.go +++ b/go/types/labels.go @@ -10,7 +10,7 @@ import ( ) // labels checks correct label use in body. -func (check *checker) labels(body *ast.BlockStmt) { +func (check *Checker) labels(body *ast.BlockStmt) { // set of all labels in this body all := NewScope(nil, "label") @@ -87,7 +87,7 @@ func (b *block) enclosingTarget(name string) *ast.LabeledStmt { // blockBranches processes a block's statement list and returns the set of outgoing forward jumps. // all is the scope of all declared labels, parent the set of labels declared in the immediately // enclosing block, and lstmt is the labeled statement this block is associated with (or nil). -func (check *checker) blockBranches(all *Scope, parent *block, lstmt *ast.LabeledStmt, list []ast.Stmt) []*ast.BranchStmt { +func (check *Checker) blockBranches(all *Scope, parent *block, lstmt *ast.LabeledStmt, list []ast.Stmt) []*ast.BranchStmt { b := &block{parent: parent, lstmt: lstmt} var ( diff --git a/go/types/ordering.go b/go/types/ordering.go index 14584c71..0052f7c8 100644 --- a/go/types/ordering.go +++ b/go/types/ordering.go @@ -23,7 +23,7 @@ import ( // in the process check _and_ report type cycles. This may simplify // the full type-checking phase. // -func (check *checker) resolveOrder() []Object { +func (check *Checker) resolveOrder() []Object { var ifaces, others []Object // collect interface types with their dependencies, and all other objects @@ -72,7 +72,7 @@ func (check *checker) resolveOrder() []Object { } // interfaceFor returns the AST interface denoted by obj, or nil. -func (check *checker) interfaceFor(obj Object) *ast.InterfaceType { +func (check *Checker) interfaceFor(obj Object) *ast.InterfaceType { tname, _ := obj.(*TypeName) if tname == nil { return nil // not a type @@ -89,7 +89,7 @@ func (check *checker) interfaceFor(obj Object) *ast.InterfaceType { return ityp } -func (check *checker) appendInPostOrder(order *[]Object, obj Object) { +func (check *Checker) appendInPostOrder(order *[]Object, obj Object) { d := check.objMap[obj] if d.mark != 0 { // We've already seen this object; either because it's diff --git a/go/types/resolver.go b/go/types/resolver.go index 1375c38c..33333537 100644 --- a/go/types/resolver.go +++ b/go/types/resolver.go @@ -48,7 +48,7 @@ func (d *declInfo) addDep(obj Object) { // have the appropriate number of names and init exprs. For const // decls, init is the value spec providing the init exprs; for // var decls, init is nil (the init exprs are in s in this case). -func (check *checker) arityMatch(s, init *ast.ValueSpec) { +func (check *Checker) arityMatch(s, init *ast.ValueSpec) { l := len(s.Names) r := len(s.Values) if init != nil { @@ -97,7 +97,7 @@ func validatedImportPath(path string) (string, error) { // declarePkgObj declares obj in the package scope, records its ident -> obj mapping, // and updates check.objMap. The object must not be a function or method. -func (check *checker) declarePkgObj(ident *ast.Ident, obj Object, d *declInfo) { +func (check *Checker) declarePkgObj(ident *ast.Ident, obj Object, d *declInfo) { assert(ident.Name == obj.Name()) // spec: "A package-scope or file-scope identifier with name init @@ -114,7 +114,7 @@ func (check *checker) declarePkgObj(ident *ast.Ident, obj Object, d *declInfo) { // collectObjects collects all file and package objects and inserts them // into their respective scopes. It also performs imports and associates // methods with receiver base type names. -func (check *checker) collectObjects() { +func (check *Checker) collectObjects() { pkg := check.pkg importer := check.conf.Import @@ -350,7 +350,7 @@ func (check *checker) collectObjects() { } // packageObjects typechecks all package objects in objList, but not function bodies. -func (check *checker) packageObjects(objList []Object) { +func (check *Checker) packageObjects(objList []Object) { // add new methods to already type-checked types (from a prior Checker.Files call) for _, obj := range objList { if obj, _ := obj.(*TypeName); obj != nil && obj.typ != nil { @@ -373,14 +373,14 @@ func (check *checker) packageObjects(objList []Object) { } // functionBodies typechecks all function bodies. -func (check *checker) functionBodies() { +func (check *Checker) functionBodies() { for _, f := range check.funcs { check.funcBody(f.decl, f.name, f.sig, f.body) } } // unusedImports checks for unused imports. -func (check *checker) unusedImports() { +func (check *Checker) unusedImports() { // if function bodies are not checked, packages' uses are likely missing - don't check if check.conf.IgnoreFuncBodies { return diff --git a/go/types/return.go b/go/types/return.go index f16a318b..5b128e2a 100644 --- a/go/types/return.go +++ b/go/types/return.go @@ -14,7 +14,7 @@ import ( // isTerminating reports if s is a terminating statement. // If s is labeled, label is the label name; otherwise s // is "". -func (check *checker) isTerminating(s ast.Stmt, label string) bool { +func (check *Checker) isTerminating(s ast.Stmt, label string) bool { switch s := s.(type) { default: unreachable() @@ -82,12 +82,12 @@ func (check *checker) isTerminating(s ast.Stmt, label string) bool { return false } -func (check *checker) isTerminatingList(list []ast.Stmt, label string) bool { +func (check *Checker) isTerminatingList(list []ast.Stmt, label string) bool { n := len(list) return n > 0 && check.isTerminating(list[n-1], label) } -func (check *checker) isTerminatingSwitch(body *ast.BlockStmt, label string) bool { +func (check *Checker) isTerminatingSwitch(body *ast.BlockStmt, label string) bool { hasDefault := false for _, s := range body.List { cc := s.(*ast.CaseClause) diff --git a/go/types/stmt.go b/go/types/stmt.go index 92fd730e..e7581f88 100644 --- a/go/types/stmt.go +++ b/go/types/stmt.go @@ -14,7 +14,7 @@ import ( "code.google.com/p/go.tools/go/exact" ) -func (check *checker) funcBody(decl *declInfo, name string, sig *Signature, body *ast.BlockStmt) { +func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body *ast.BlockStmt) { if trace { if name == "" { name = "" @@ -53,7 +53,7 @@ func (check *checker) funcBody(decl *declInfo, name string, sig *Signature, body check.usage(sig.scope) } -func (check *checker) usage(scope *Scope) { +func (check *Checker) usage(scope *Scope) { for _, obj := range scope.elems { if v, _ := obj.(*Var); v != nil && !v.used { check.softErrorf(v.pos, "%s declared but not used", v.name) @@ -74,13 +74,13 @@ const ( inContinuable ) -func (check *checker) initStmt(s ast.Stmt) { +func (check *Checker) initStmt(s ast.Stmt) { if s != nil { check.stmt(0, s) } } -func (check *checker) stmtList(ctxt stmtContext, list []ast.Stmt) { +func (check *Checker) stmtList(ctxt stmtContext, list []ast.Stmt) { ok := ctxt&fallthroughOk != 0 inner := ctxt &^ fallthroughOk for i, s := range list { @@ -92,7 +92,7 @@ func (check *checker) stmtList(ctxt stmtContext, list []ast.Stmt) { } } -func (check *checker) multipleDefaults(list []ast.Stmt) { +func (check *Checker) multipleDefaults(list []ast.Stmt) { var first ast.Stmt for _, s := range list { var d ast.Stmt @@ -118,13 +118,13 @@ func (check *checker) multipleDefaults(list []ast.Stmt) { } } -func (check *checker) openScope(s ast.Stmt, comment string) { +func (check *Checker) openScope(s ast.Stmt, comment string) { scope := NewScope(check.scope, comment) check.recordScope(s, scope) check.scope = scope } -func (check *checker) closeScope() { +func (check *Checker) closeScope() { check.scope = check.scope.Parent() } @@ -136,7 +136,7 @@ func assignOp(op token.Token) token.Token { return token.ILLEGAL } -func (check *checker) suspendedCall(keyword string, call *ast.CallExpr) { +func (check *Checker) suspendedCall(keyword string, call *ast.CallExpr) { var x operand var msg string switch check.rawExpr(&x, call, nil) { @@ -152,7 +152,7 @@ func (check *checker) suspendedCall(keyword string, call *ast.CallExpr) { check.errorf(x.pos(), "%s %s %s", keyword, msg, &x) } -func (check *checker) caseValues(x operand /* copy argument (not *operand!) */, values []ast.Expr) { +func (check *Checker) caseValues(x operand /* copy argument (not *operand!) */, values []ast.Expr) { // No duplicate checking for now. See issue 4524. for _, e := range values { var y operand @@ -174,7 +174,7 @@ func (check *checker) caseValues(x operand /* copy argument (not *operand!) */, } } -func (check *checker) caseTypes(x *operand, xtyp *Interface, types []ast.Expr, seen map[Type]token.Pos) (T Type) { +func (check *Checker) caseTypes(x *operand, xtyp *Interface, types []ast.Expr, seen map[Type]token.Pos) (T Type) { L: for _, e := range types { T = check.typOrNil(e) @@ -200,7 +200,7 @@ L: } // stmt typechecks statement s. -func (check *checker) stmt(ctxt stmtContext, s ast.Stmt) { +func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) { // statements cannot use iota in general // (constant declarations set it explicitly) assert(check.iota == nil) diff --git a/go/types/typexpr.go b/go/types/typexpr.go index f5a42cd2..57861e4c 100644 --- a/go/types/typexpr.go +++ b/go/types/typexpr.go @@ -19,7 +19,7 @@ import ( // If an error occurred, x.mode is set to invalid. // For the meaning of def and path, see check.typ, below. // -func (check *checker) ident(x *operand, e *ast.Ident, def *Named, path []*TypeName) { +func (check *Checker) ident(x *operand, e *ast.Ident, def *Named, path []*TypeName) { x.mode = invalid x.expr = e @@ -117,7 +117,7 @@ func (check *checker) ident(x *operand, e *ast.Ident, def *Named, path []*TypeNa // any components of e are type-checked. Path contains the path of named types // referring to this type. // -func (check *checker) typExpr(e ast.Expr, def *Named, path []*TypeName) (T Type) { +func (check *Checker) typExpr(e ast.Expr, def *Named, path []*TypeName) (T Type) { if trace { check.trace(e.Pos(), "%s", e) check.indent++ @@ -134,12 +134,12 @@ func (check *checker) typExpr(e ast.Expr, def *Named, path []*TypeName) (T Type) return } -func (check *checker) typ(e ast.Expr) Type { +func (check *Checker) typ(e ast.Expr) Type { return check.typExpr(e, nil, nil) } // funcType type-checks a function or method type and returns its signature. -func (check *checker) funcType(sig *Signature, recv *ast.FieldList, ftyp *ast.FuncType) *Signature { +func (check *Checker) funcType(sig *Signature, recv *ast.FieldList, ftyp *ast.FuncType) *Signature { scope := NewScope(check.scope, "function") check.recordScope(ftyp, scope) @@ -198,7 +198,7 @@ func (check *checker) funcType(sig *Signature, recv *ast.FieldList, ftyp *ast.Fu // typExprInternal drives type checking of types. // Must only be called by typExpr. // -func (check *checker) typExprInternal(e ast.Expr, def *Named, path []*TypeName) Type { +func (check *Checker) typExprInternal(e ast.Expr, def *Named, path []*TypeName) Type { switch e := e.(type) { case *ast.BadExpr: // ignore - error reported before @@ -334,7 +334,7 @@ func (check *checker) typExprInternal(e ast.Expr, def *Named, path []*TypeName) // and returns the typ of e, or nil. // If e is neither a type nor nil, typOrNil returns Typ[Invalid]. // -func (check *checker) typOrNil(e ast.Expr) Type { +func (check *Checker) typOrNil(e ast.Expr) Type { var x operand check.rawExpr(&x, e, nil) switch x.mode { @@ -355,7 +355,7 @@ func (check *checker) typOrNil(e ast.Expr) Type { return Typ[Invalid] } -func (check *checker) arrayLength(e ast.Expr) int64 { +func (check *Checker) arrayLength(e ast.Expr) int64 { var x operand check.expr(&x, e) if x.mode != constant { @@ -376,7 +376,7 @@ func (check *checker) arrayLength(e ast.Expr) int64 { return n } -func (check *checker) collectParams(scope *Scope, list *ast.FieldList, variadicOk bool) (params []*Var, variadic bool) { +func (check *Checker) collectParams(scope *Scope, list *ast.FieldList, variadicOk bool) (params []*Var, variadic bool) { if list == nil { return } @@ -431,7 +431,7 @@ func (check *checker) collectParams(scope *Scope, list *ast.FieldList, variadicO return } -func (check *checker) declareInSet(oset *objset, pos token.Pos, obj Object) bool { +func (check *Checker) declareInSet(oset *objset, pos token.Pos, obj Object) bool { if alt := oset.insert(obj); alt != nil { check.errorf(pos, "%s redeclared", obj.Name()) check.reportAltDecl(alt) @@ -440,7 +440,7 @@ func (check *checker) declareInSet(oset *objset, pos token.Pos, obj Object) bool return true } -func (check *checker) interfaceType(iface *Interface, ityp *ast.InterfaceType, def *Named, path []*TypeName) { +func (check *Checker) interfaceType(iface *Interface, ityp *ast.InterfaceType, def *Named, path []*TypeName) { // empty interface: common case if ityp.Methods == nil { return @@ -589,7 +589,7 @@ func (a byUniqueMethodName) Len() int { return len(a) } func (a byUniqueMethodName) Less(i, j int) bool { return a[i].Id() < a[j].Id() } func (a byUniqueMethodName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (check *checker) tag(t *ast.BasicLit) string { +func (check *Checker) tag(t *ast.BasicLit) string { if t != nil { if t.Kind == token.STRING { if val, err := strconv.Unquote(t.Value); err == nil { @@ -601,7 +601,7 @@ func (check *checker) tag(t *ast.BasicLit) string { return "" } -func (check *checker) structType(styp *Struct, e *ast.StructType, path []*TypeName) { +func (check *Checker) structType(styp *Struct, e *ast.StructType, path []*TypeName) { list := e.Fields if list == nil { return