]> Cypherpunks repositories - gostls13.git/commitdiff
Fix declared and not used errors and unused import errors in
authorAustin Clements <aclements@csail.mit.edu>
Thu, 24 Sep 2009 15:25:14 +0000 (08:25 -0700)
committerAustin Clements <aclements@csail.mit.edu>
Thu, 24 Sep 2009 15:25:14 +0000 (08:25 -0700)
the interpreter and update code to use ast.BasicDecl and
multi-type switch.  There are still a lot of "switch _ :=
x.(type)" that should make use of the new type switch syntax,
but those will be a different CL.

R=rsc
APPROVED=rsc
DELTA=58  (16 added, 23 deleted, 19 changed)
OCL=34853
CL=34963

usr/austin/eval/compiler.go
usr/austin/eval/expr.go
usr/austin/eval/scope.go
usr/austin/eval/stmt.go
usr/austin/eval/type.go
usr/austin/eval/typec.go
usr/austin/eval/util.go
usr/austin/eval/world.go

index 12cace9e0cbaf077fbb535b06d0619c2838bfc53..f3c962c2b729566cc2020a2d804458675ae6364b 100644 (file)
@@ -6,7 +6,6 @@ package eval
 
 import (
        "fmt";
-       "go/ast";
        "go/scanner";
        "go/token";
 )
index 472db83c189edbcf2401615867c2b29ce3d4f45c..5c4e7924917c150e9ec0a0da79b1f24b18588a19 100644 (file)
@@ -7,10 +7,8 @@ package eval
 import (
        "bignum";
        "go/ast";
-       "go/scanner";
        "go/token";
        "log";
-       "os";
        "strconv";
        "strings";
 )
@@ -191,7 +189,7 @@ func (a *expr) convertToInt(max int64, negErr string, errOp string) *expr {
 // expression.
 func (a *expr) derefArray() *expr {
        if pt, ok := a.t.lit().(*PtrType); ok {
-               if at, ok := pt.Elem.lit().(*ArrayType); ok {
+               if _, ok := pt.Elem.lit().(*ArrayType); ok {
                        deref := a.compileStarExpr(a);
                        if deref == nil {
                                log.Crashf("failed to dereference *array");
@@ -481,15 +479,23 @@ func (a *exprCompiler) compile(x ast.Expr, callCtx bool) *expr {
 
        switch x := x.(type) {
        // Literals
-       case *ast.CharLit:
-               return ei.compileCharLit(string(x.Value));
+       case *ast.BasicLit:
+               switch x.Kind {
+               case token.INT:
+                       return ei.compileIntLit(string(x.Value));
+               case token.FLOAT:
+                       return ei.compileFloatLit(string(x.Value));
+               case token.CHAR:
+                       return ei.compileCharLit(string(x.Value));
+               case token.STRING:
+                       return ei.compileStringLit(string(x.Value));
+               default:
+                       log.Crashf("unexpected basic literal type %v", x.Kind);
+               }
 
        case *ast.CompositeLit:
                goto notimpl;
 
-       case *ast.FloatLit:
-               return ei.compileFloatLit(string(x.Value));
-
        case *ast.FuncLit:
                decl := ei.compileFuncType(a.block, x.Type);
                if decl == nil {
@@ -507,12 +513,6 @@ func (a *exprCompiler) compile(x ast.Expr, callCtx bool) *expr {
                }
                return ei.compileFuncLit(decl, fn);
 
-       case *ast.IntLit:
-               return ei.compileIntLit(string(x.Value));
-
-       case *ast.StringLit:
-               return ei.compileStringLit(string(x.Value));
-
        // Types
        case *ast.ArrayType:
                // TODO(austin) Use a multi-type case
@@ -744,7 +744,7 @@ func (a *exprInfo) compileIdealInt(i *bignum.Integer, desc string) *expr {
 }
 
 func (a *exprInfo) compileIntLit(lit string) *expr {
-       i, _, _2 := bignum.IntFromString(lit, 0);
+       i, _, _ := bignum.IntFromString(lit, 0);
        return a.compileIdealInt(i, "integer literal");
 }
 
@@ -754,7 +754,7 @@ func (a *exprInfo) compileCharLit(lit string) *expr {
                a.silentErrors++;
                return nil;
        }
-       v, mb, tail, err := strconv.UnquoteChar(lit[1:len(lit)], '\'');
+       v, _, tail, err := strconv.UnquoteChar(lit[1:len(lit)], '\'');
        if err != nil || tail != "'" {
                // Caught by parser
                a.silentErrors++;
@@ -863,7 +863,7 @@ func (a *exprInfo) compileSelectorExpr(v *expr, name string) *expr {
 
                // If it's a named type, look for methods
                if ti, ok := t.(*NamedType); ok {
-                       method, ok := ti.methods[name];
+                       _, ok := ti.methods[name];
                        if ok {
                                mark(depth, pathName + "." + name);
                                log.Crash("Methods not implemented");
@@ -1638,12 +1638,8 @@ func (a *exprInfo) compileBinaryExpr(op token.Token, l, r *expr) *expr {
                        return nil;
                }
                // Arrays and structs may not be compared to anything.
-               // TODO(austin) Use a multi-type switch
-               if _, ok := l.t.(*ArrayType); ok {
-                       a.diagOpTypes(op, origlt, origrt);
-                       return nil;
-               }
-               if _, ok := l.t.(*StructType); ok {
+               switch l.t.(type) {
+               case *ArrayType, *StructType:
                        a.diagOpTypes(op, origlt, origrt);
                        return nil;
                }
index 7e10293d5d89301cec895cfeb513380f11ec5942..7ee4a8915ee2d62e6832a2a87035a4cde005f766 100644 (file)
@@ -5,7 +5,6 @@
 package eval
 
 import (
-       "fmt";
        "go/token";
        "log";
 )
index 758157827c903d38944a4a8ae253a0da041b90d9..9ec6fb83df400dd02e97fe414b5bafb4b3358d6c 100644 (file)
@@ -7,11 +7,8 @@ package eval
 import (
        "bignum";
        "log";
-       "os";
        "go/ast";
-       "go/scanner";
        "go/token";
-       "strconv";
 )
 
 const (
@@ -1018,7 +1015,7 @@ func (a *stmtCompiler) compileSwitchStmt(s *ast.SwitchStmt) {
        // Count cases
        ncases := 0;
        hasDefault := false;
-       for i, c := range s.Body.List {
+       for _, c := range s.Body.List {
                clause, ok := c.(*ast.CaseClause);
                if !ok {
                        a.diagAt(clause, "switch statement must contain case clauses");
@@ -1090,7 +1087,7 @@ func (a *stmtCompiler) compileSwitchStmt(s *ast.SwitchStmt) {
                // Save jump PC's
                pc := a.nextPC();
                if clause.Values != nil {
-                       for _, v := range clause.Values {
+                       for _ = range clause.Values {
                                casePCs[i] = &pc;
                                i++;
                        }
@@ -1215,7 +1212,7 @@ func (a *blockCompiler) compileStmt(s ast.Stmt) {
 }
 
 func (a *blockCompiler) compileStmts(block *ast.BlockStmt) {
-       for i, sub := range block.List {
+       for _, sub := range block.List {
                a.compileStmt(sub);
        }
 }
index 65610844544ab1e589586c6762bfbbf3e56a1fb5..b73f9216385eeb1d17709886d15d7b9bdd7f146e 100644 (file)
@@ -165,7 +165,7 @@ type boolType struct {
 var BoolType = universe.DefineType("bool", universePos, &boolType{})
 
 func (t *boolType) compat(o Type, conv bool) bool {
-       t2, ok := o.lit().(*boolType);
+       _, ok := o.lit().(*boolType);
        return ok;
 }
 
@@ -364,7 +364,7 @@ type idealIntType struct {
 var IdealIntType Type = &idealIntType{}
 
 func (t *idealIntType) compat(o Type, conv bool) bool {
-       t2, ok := o.lit().(*idealIntType);
+       _, ok := o.lit().(*idealIntType);
        return ok;
 }
 
@@ -485,7 +485,7 @@ type idealFloatType struct {
 var IdealFloatType Type = &idealFloatType{};
 
 func (t *idealFloatType) compat(o Type, conv bool) bool {
-       t2, ok := o.lit().(*idealFloatType);
+       _, ok := o.lit().(*idealFloatType);
        return ok;
 }
 
@@ -520,7 +520,7 @@ type stringType struct {
 var StringType = universe.DefineType("string", universePos, &stringType{})
 
 func (t *stringType) compat(o Type, conv bool) bool {
-       t2, ok := o.lit().(*stringType);
+       _, ok := o.lit().(*stringType);
        return ok;
 }
 
index a4d055fb5926167402de1d40e32b1d7454c16db2..dcff93ccb47779591dc28307a3be9196a9651c4c 100644 (file)
@@ -26,7 +26,7 @@ type typeCompiler struct {
 }
 
 func (a *typeCompiler) compileIdent(x *ast.Ident, allowRec bool) Type {
-       _bl, _index, def := a.block.Lookup(x.Value);
+       _, _, def := a.block.Lookup(x.Value);
        if def == nil {
                a.diagAt(x, "%s: undefined", x.Value);
                return nil;
@@ -106,7 +106,7 @@ func (a *typeCompiler) compileFields(fs []*ast.Field, allowRec bool) ([]Type, []
 
        bad := false;
        i := 0;
-       for fi, f := range fs {
+       for _, f := range fs {
                t := a.compileType(f.Type, allowRec);
                if t == nil {
                        bad = true;
index 68f58842d45acabc1c8b67f26b9e7a89f45b8a74..9cdf23722144d33fb4105fee89101ca7ea3c406b 100644 (file)
@@ -6,8 +6,6 @@ package eval
 
 import (
        "bignum";
-       "fmt";
-       "go/token";
 )
 
 // TODO(austin): Maybe add to bignum in more general form
index 6738f6b50c80c6c6f3bdf3426552ad0ab7dde3e2..4eba216bb91716be899e440cbad950606dd58d1c 100644 (file)
@@ -5,7 +5,6 @@
 package eval
 
 import (
-       "fmt";
        "go/ast";
        "go/parser";
        "go/scanner";
@@ -64,7 +63,7 @@ func (w *World) compileStmts(stmts []ast.Stmt) (Code, os.Error) {
                block: w.scope.block,
        };
        nerr := cc.numError();
-       for i, stmt := range stmts {
+       for _, stmt := range stmts {
                bc.compileStmt(stmt);
        }
        fc.checkLabels();
@@ -107,11 +106,16 @@ func (w *World) compileExpr(e ast.Expr) (Code, os.Error) {
                return nil, errors.GetError(scanner.Sorted);
        }
        var eval func(Value, *Thread);
-       switch _ := ec.t.(type) {
+       switch t := ec.t.(type) {
        case *idealIntType:
                // nothing
        case *idealFloatType:
                // nothing
+       case *MultiType:
+               if len(t.Elems) == 0 {
+                       return &stmtCode{w, code{ec.exec}}, nil;
+               }
+               fallthrough;
        default:
                eval = genAssign(ec.t, ec);
        }