You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: rewrite.go
    path of file: ./repos/gapid/test/robot/lingo/generator
    
    the code of the file until where you have to start completion: // Copyright (C) 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package generator

import (
	"context"
	"fmt"
	"go/ast"
	"go/token"
	"strings"
)

type rewriter struct {
	uid   int
	funcs map[string]*entry
	fun   *entry
}

func (info *introspection) rewrite(ctx context.Context) {
	// Do the initial rewrites
	for _, e := range info.entries {
		if e.Func != nil {
			r := &rewriter{
				funcs: info.byName,
				fun:   e,
			}
			r.rewriteBlock(e.Func.Body)
		}
	}
	// Add any additional function forms we need
	for _, e := range info.entries {
		generateFor(ctx, info.fset, e)
	}
	// Map and default values needed to the first file they are seen in
	defined := map[string]bool{}
	for
    
func (r *rewriter) rewriteStatement(stmts *[]ast.Stmt, stmt ast.Stmt) ast.Stmt {
	switch stmt := stmt.(type) {
	case *ast.BlockStmt:
		r.rewriteBlock(stmt)
	case *ast.ExprStmt:
		call := r.checkCall(stmt.X)
		if call != nil {
			// Direct call, replace it
			return r.errTest("err", &ast.AssignStmt{
				Lhs: []ast.Expr{
					&ast.Ident{Name: "_"},
					&ast.Ident{Name: "err"},
				},
				Tok: token.DEFINE,
				Rhs: []ast.Expr{call},
			})
		}
	case *ast.AssignStmt:
		for i, expr := range stmt.Lhs {
			stmt.Lhs[i] = r.liftValueExpression(stmts, expr)
		}
		if len(stmt.Lhs) != 2 || len(stmt.Rhs) != 1 || r.checkCall(stmt.Rhs[0]) == nil {
			for i, expr := range stmt.Rhs {
				stmt.Rhs[i] = r.liftValueExpression(stmts, expr)
			}
		}
	case *ast.ReturnStmt:
		if len(stmt.Results) == 1 {
			r.checkCall(stmt.Results[0])
		} else {
			for i, expr := range stmt.Results {
				stmt.Results[i] = r.liftValueExpression(stmts, expr)
			}
		}
	case *ast.IfStmt:
		count := len(*stmts)
		stmt.Cond = r.liftBoolExpression(stmts, stmt.Cond)
		if stmt.Init != nil {
			stmt.Init = r.rewriteStatement(stmts, stmt.Init)
		} else if len(*stmts) == count+1 {
			stmt.Init = (*stmts)[count]
			*stmts = (*stmts)[:count]
		}
		r.rewriteBlock(stmt.Body)
		if stmt.Else != nil {
			count = len(*stmts)
			stmt.Else = r.rewriteStatement(stmts, stmt.Else)
			if len(*stmts) != count {
				stmt.Else = &ast.BadStmt{}
			}
		}
	case *ast.ForStmt:
		id := r.UID()
		mark := &ast.Ident{Name: fmt.Sprint("forMark", id)}
		err := &ast.Ident{Name: fmt.Sprint("forErr", id)}
		*stmts = append(*stmts,
			&ast.AssignStmt{
				Lhs: []ast.Expr{mark},
				Tok: token.DEFINE,
				Rhs: []ast.Expr{
					&ast.CallExpr{
						Fun: &ast.SelectorExpr{
							X:   &ast.Ident{Name: r.fun.Params[0].Names[0].Name},
							Sel: &ast.Ident{Name: "PreMark"},
						},
						Args: []ast.Expr{},
					},
				},
			},
			&ast.DeclStmt{
				Decl: &ast.GenDecl{
					Tok: token.VAR,
					Specs: []ast.Spec{&ast.ValueSpec{
						Names: []*ast.Ident{err},
						Type:  &ast.Ident{Name: "error"},
					}},
				},
			},
		)
		stmt.Cond = r.liftBoolExpression(stmts, stmt.Cond)
		r.rewriteBlock(stmt.Body)
		stmt.Body.List = append([]ast.Stmt{
			r.errTest(err.Name, &ast.AssignStmt{
				Lhs: []ast.Expr{mark, err},
				Tok: token.ASSIGN,
				Rhs: []ast.Expr{
					&ast.CallExpr{
						Fun: &ast.SelectorExpr{
							X:   &ast.Ident{Name: r.fun.Params[0].Names[0].Name},
							Sel: &ast.Ident{Name: "MustProgress"},
						},
						Args: []ast.Expr{mark},
					},
				},
			}),
		}, stmt.Body.List...)
	case *ast.DeclStmt:
		// TODO:
	case *ast.LabeledStmt:
		stmt.Stmt = r.rewriteStatement(stmts, stmt.Stmt)
	case *ast.SendStmt:
		stmt.Chan = r.liftValueExpression(stmts, stmt.Chan)
		stmt.Value = r.liftValueExpression(stmts, stmt.Value)
	case *ast.IncDecStmt:
		stmt.X = r.liftValueExpression(stmts, stmt.X)
	case *ast.SwitchStmt:
		stmt.Init = r.rewriteStatement(stmts, stmt.Init)
		r.rewriteBlock(stmt.Body)
	case *ast.CaseClause:
		var extras []ast.Stmt
		for i, expr := range stmt.List {
			stmt.List[i] = r.liftBoolExpression(&extras, expr)
		}
		body := []ast.Stmt{}
		if len(extras) != 0 {
			body = append(body, &ast.BadStmt{})
			body = append(body, extras...)
			body = append(body, &ast.BadStmt{})
		}
		for _, stmt := range stmt.Body {
			body = append(body, r.rewriteStatement(&body, stmt))
		}
		stmt.Body = body
	case *ast.TypeSwitchStmt:
		stmt.Init = r.rewriteStatement(stmts, stmt.Init)
		stmt.Assign = r.rewriteStatement(stmts, stmt.Assign)
		r.rewriteBlock(stmt.Body)
	case *ast.SelectStmt:
		r.rewriteBlock(stmt.Body)
	case *ast.CommClause:
		stmt.Comm = r.rewriteStatement(stmts, stmt.Comm)
		body := []ast.Stmt{}
		for _, stmt := range stmt.Body {
			body = append(body, r.rewriteStatement(&body, stmt))
		}
		stmt.Body = body
	case *ast.RangeStmt:
		stmt.X = r.liftValueExpression(stmts, stmt.X)
		r.rewriteBlock(stmt.Body)
	}
	return stmt
}