checktype.go 822 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
package transform

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

/*
11
12
13
The TypeChecker triggers errors for uses of :
 - Non-integer variable
 - Channel
14
15
16
17
18
19
20
21
22
23
24
25
26
27
*/

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 {
28
					fmt.Println("Non-integer values are not supported.")
29
30
31
32
33
					fmt.Println("Identified type :", rhn.Kind)
					os.Exit(1)
				}
			}
		}
34
35
36
	case *ast.ChanType:
		fmt.Println("Channels are not supported.")
		os.Exit(1)
37
38
39
40
41
42
43
	}
	return true
}

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