コード例 #1
0
ファイル: misc.go プロジェクト: dansawkins/ark
func (v *MiscCheck) Visit(s *SemanticAnalyzer, n parser.Node) {
	if _, ok := n.(*parser.FunctionDecl); ok {
		v.InFunction++
	}

	if v.InFunction <= 0 {
		switch n.(type) {
		case *parser.ReturnStat:
			s.Err(n, "%s must be in function", util.CapitalizeFirst(n.NodeName()))
		}
	} else {
		switch n.(type) {
		case *parser.TypeDecl:
			s.Err(n, "%s must not be in function", util.CapitalizeFirst(n.NodeName()))
		}
	}
}
コード例 #2
0
ファイル: misc.go プロジェクト: kiljacken/ark
func (v *MiscCheck) Visit(s *SemanticAnalyzer, n ast.Node) {
	switch n.(type) {
	case *ast.FunctionDecl, *ast.LambdaExpr:
		v.InFunction++
	}

	if v.InFunction <= 0 {
		switch n.(type) {
		case *ast.ReturnStat:
			s.Err(n, "%s must be in function", util.CapitalizeFirst(n.NodeName()))
		}
	} else {
		switch n.(type) {
		case *ast.TypeDecl:
			s.Err(n, "%s must not be in function", util.CapitalizeFirst(n.NodeName()))

		case *ast.FunctionDecl:
			if v.InFunction > 1 {
				s.Err(n, "%s must not be in function", util.CapitalizeFirst(n.NodeName()))
			}
		}
	}
}
コード例 #3
0
ファイル: break_next.go プロジェクト: kiljacken/ark
func (v *BreakAndNextCheck) Visit(s *SemanticAnalyzer, n ast.Node) {
	switch n := n.(type) {
	case *ast.NextStat, *ast.BreakStat:
		if v.nestedLoopCount[v.functions[len(v.functions)-1]] == 0 {
			s.Err(n, "%s must be in a loop", util.CapitalizeFirst(n.NodeName()))
		}

	case *ast.LoopStat:
		v.nestedLoopCount[v.functions[len(v.functions)-1]]++

	case *ast.FunctionDecl:
		v.functions = append(v.functions, n.Function)
	case *ast.LambdaExpr:
		v.functions = append(v.functions, n.Function)
	}
}