checktype.go 733 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package transform

import (
	"fmt"
	"go/ast"
	"go/token"
	"os"
)

/*
The TypeChecker check if there is other types, variable must be declared
as integer.
*/

type TypeChecker struct {
}

// Pre traversal check if there is use of variable other than integers.
func (t *TypeChecker) Pre(meta *Meta, v *Visitor) bool {
	c := v.Cursor()
	switch node := c.Node().(type) {
	case *ast.AssignStmt:
		for i := 0; i < len(node.Rhs); i++ {
			switch rhn := node.Rhs[i].(type) {
			case *ast.BasicLit:
				if rhn.Kind != token.INT {
					fmt.Println("Values must be integer.")
					fmt.Println("Identified type :", rhn.Kind)
					os.Exit(1)
				}
			}
		}
	}
	return true
}

func (TypeChecker) Post(meta *Meta, v *Visitor) bool {
	return true
}