Exemple #1
0
func (sc *PackageScoping) MangleStatement(st ast.Stmt) {
	switch st := st.(type) {
	case *ast.IncDecStmt:
		sc.MangleExpr(st.X)
	case *ast.BlockStmt:
		if st != nil && st.List != nil {
			for _, x := range st.List {
				sc.MangleStatement(x)
			}
		}
	case *ast.ForStmt:
		sc.MangleStatement(st.Post)
		sc.MangleExpr(st.Cond)
		sc.MangleStatement(st.Body)
		sc.MangleStatement(st.Init)
	case *ast.IfStmt:
		sc.MangleStatement(st.Init)
		sc.MangleExpr(st.Cond)
		sc.MangleStatement(st.Body)
		sc.MangleStatement(st.Else)
	case *ast.AssignStmt:
		for i := range st.Lhs {
			st.Lhs[i] = sc.MangleExpr(st.Lhs[i])
		}
		for i := range st.Rhs {
			st.Rhs[i] = sc.MangleExpr(st.Rhs[i])
		}
	case *ast.ExprStmt:
		sc.MangleExpr(st.X)
	case *ast.DeclStmt:
		switch decl := st.Decl.(type) {
		case *ast.GenDecl:
			if decl.Tok != token.VAR {
				panic(fmt.Sprint("I don't understand decl with tok", decl.Tok))
			}
			for _, spec := range decl.Specs {
				s := spec.(*ast.ValueSpec)
				sc.MangleExpr(s.Type)
				for _, v := range s.Values {
					sc.MangleExpr(v)
				}
			}
		default:
			panic("Weird Decl here...")
		}
	case *ast.ReturnStmt:
		for _, e := range st.Results {
			sc.MangleExpr(e)
		}
	case *ast.RangeStmt:
		st.Key = sc.MangleExpr(st.Key)
		st.Value = sc.MangleExpr(st.Value)
		st.X = sc.MangleExpr(st.X)
		sc.MangleStatement(st.Body)
	case *ast.SwitchStmt:
		st.Tag = sc.MangleExpr(st.Tag)
		sc.MangleStatement(st.Init)
		sc.MangleStatement(st.Body)
	case *ast.CaseClause:
		for i := range st.List {
			st.List[i] = sc.MangleExpr(st.List[i])
		}
		for _, st2 := range st.Body {
			sc.MangleStatement(st2)
		}
	case nil:
		// Nothing to do with a statement of type nil!
	default:
		panic(fmt.Sprintf("Tracked weird statement of type %T", st))
	}
}