// AcceptArithmetic implements Visitor
979097
func (t *typeChecker) AcceptArithmetic(v tree.Arithmetic) {
	if t.expectBoolean {
		t.result = fmt.Errorf("expected boolean expression but found: %s", tree.ExpressionString(v))
		return
	}

	res := either(
		typeCheckExpectingNumeric(v.Left),
		typeCheckExpectingNumeric(v.Right))
	if res != nil {
		t.result = res
	}
}
862325
func (s *arithmeticSimplifier) AcceptBinaryNegation(v tree.BinaryNegation) {
	val := s.Transform(v.Operand)
	if val2, ok := potentialExtractValue(val); ok {
		s.Result = tree.NumericLiteral{^val2}
	}
}
413264
func DoArithmetic(a, b interface{}, op rune) (interface{}, error) {
	av := reflect.ValueOf(a)
	bv := reflect.ValueOf(b)
	var ai, bi int64
	var af, bf float64
	var au, bu uint64
	switch av.Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		ai = av.Int()
		switch bv.Kind() {
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
			bi = bv.Int()
		case reflect.Float32, reflect.Float64:
			af = float64(ai) // may overflow
			ai = 0
			bf = bv.Float()
		case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
			bu = bv.Uint()
			if ai >= 0 {
				au = uint64(ai)
				ai = 0
			} else {
				bi = int64(bu) // may overflow
				bu = 0
			}
		default:
			return nil, errors.New("can't apply the operator to the values")
		}
	case reflect.Float32, reflect.Float64:
		af = av.Float()
		switch bv.Kind() {
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
			bf = float64(bv.Int()) // may overflow
		case reflect.Float32, reflect.Float64:
			bf = bv.Float()
		case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
			bf = float64(bv.Uint()) // may overflow
		default:
			return nil, errors.New("can't apply the operator to the values")
		}
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		au = av.Uint()
		switch bv.Kind() {
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
			bi = bv.Int()
			if bi >= 0 {
				bu = uint64(bi)
				bi = 0
			} else {
				ai = int64(au) // may overflow
				au = 0
			}
		case reflect.Float32, reflect.Float64:
			af = float64(au) // may overflow
			au = 0
			bf = bv.Float()
		case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
			bu = bv.Uint()
		default:
			return nil, errors.New("can't apply the operator to the values")
		}
	case reflect.String:
		as := av.String()
		if bv.Kind() == reflect.String && op == '+' {
			bs := bv.String()
			return as + bs, nil
		}
		return nil, errors.New("can't apply the operator to the values")
	default:
		return nil, errors.New("can't apply the operator to the values")
	}

	switch op {
	case '+':
		if ai != 0 || bi != 0 {
			return ai + bi, nil
		} else if af != 0 || bf != 0 {
			return af + bf, nil
		} else if au != 0 || bu != 0 {
			return au + bu, nil
		}
		return 0, nil
	case '-':
		if ai != 0 || bi != 0 {
			return ai - bi, nil
		} else if af != 0 || bf != 0 {
			return af - bf, nil
		} else if au != 0 || bu != 0 {
			return au - bu, nil
		}
		return 0, nil
	case '*':
		if ai != 0 || bi != 0 {
			return ai * bi, nil
		} else if af != 0 || bf != 0 {
			return af * bf, nil
		} else if au != 0 || bu != 0 {
			return au * bu, nil
		}
		return 0, nil
	case '/':
		if bi != 0 {
			return ai / bi, nil
		} else if bf != 0 {
			return af / bf, nil
		} else if bu != 0 {
			return au / bu, nil
		}
		return nil, errors.New("can't divide the value by 0")
	default:
		return nil, errors.New("there is no such an operation")
	}
}
355148
func (t *typeChecker) AcceptComparison(v tree.Comparison) {
	if !t.expectBoolean {
		t.result = fmt.Errorf("expected numeric expression but found: %s", tree.ExpressionString(v))
		return
	}

	// This language only accepts comparisons between numeric values, so we implement that here
	res := either(
		typeCheckExpectingNumeric(v.Left),
		typeCheckExpectingNumeric(v.Right))
	if res != nil {
		t.result = res
	}
}
129655
func (s *numericCompilerVisitor) AcceptNumericLiteral(v tree.NumericLiteral) {
	s.ctx.op(OP_LOAD_VAL, uint32(v.Value))
}
812306
func (s *booleanCompilerVisitor) AcceptArithmetic(v tree.Arithmetic) {
	s.err = errors.New("arithmetic was found in a boolean expression - this is likely a programmer error")
}
540087
func (sv *StringVisitor) AcceptArithmetic(v Arithmetic) {
	sv.result = fmt.Sprintf("%s(%s ", sv.result, ArithmeticSymbols[v.Op])
	v.Left.Accept(sv)
	sv.result += " "
	v.Right.Accept(sv)
	sv.result += ")"
}
151598
func (s *EmptyTransformer) AcceptComparison(v Comparison) {
	s.Result = Comparison{
		Op:    v.Op,
		Left:  s.Transform(v.Left),
		Right: s.Transform(v.Right),
	}
}
244555
func (n *negotiator) Accepts(ctype string) float64 {
	return accepts(n.r.Header.Get("Accept"), ctype)
}
586307
func (ar *argumentRestrictions) AcceptNegation(v tree.Negation) {
	ar.register(checkRestrictedArgumentUsage(v.Operand))
}
479820
func (l *StringLexer) AcceptRunFunc(fn func(r rune) bool) bool {
	guard := Mark("AcceptRun")
	defer guard()
	return AcceptRunFunc(l, fn)
}
1353482
func (s *inclusionRemoverSimplifier) AcceptInclusion(a tree.Inclusion) {
	l := s.Transform(a.Left)
	op := tree.EQL
	combiner := combineAsOrs

	if !a.Positive {
		op = tree.NEQL
		combiner = combineAsAnds
	}

	result := make([]tree.Expression, len(a.Rights))
	for ix, v := range a.Rights {
		result[ix] = tree.Comparison{Op: op, Left: l, Right: s.Transform(v)}
	}

	s.Result = combiner(result)
}
426772
func (s *comparisonSimplifier) AcceptComparison(a tree.Comparison) {
	l := s.Transform(a.Left)
	r := s.Transform(a.Right)

	pl, ok1 := potentialExtractValue(l)
	pr, ok2 := potentialExtractValue(r)

	if ok1 && ok2 {
		switch a.Op {
		case tree.EQL:
			s.Result = tree.BooleanLiteral{pl == pr}
			return
		case tree.NEQL:
			s.Result = tree.BooleanLiteral{pl != pr}
			return
		case tree.GT:
			s.Result = tree.BooleanLiteral{pl > pr}
			return
		case tree.GTE:
			s.Result = tree.BooleanLiteral{pl >= pr}
			return
		case tree.LT:
			s.Result = tree.BooleanLiteral{pl < pr}
			return
		case tree.LTE:
			s.Result = tree.BooleanLiteral{pl <= pr}
			return
		case tree.BITSET:
			s.Result = tree.BooleanLiteral{pl&pr != 0}
			return
		}
	}
	s.Result = tree.Comparison{Op: a.Op, Left: l, Right: r}
}
1124043
func (ar *argumentRestrictions) AcceptOr(v tree.Or) {
	ar.register(either(
		checkRestrictedArgumentUsage(v.Left),
		checkRestrictedArgumentUsage(v.Right)))
}
68421
func (a *acceptUnique) Accept(from interface{}) bool {
	obj, meta, err := objectMetaData(from)
	if err != nil {
		return false
	}
	gvk, _, err := a.typer.ObjectKinds(obj)
	if err != nil {
		return false
	}
	key := fmt.Sprintf("%s/%s/%s", gvk[0].Kind, meta.GetNamespace(), meta.GetName())
	_, exists := a.objects[key]
	if exists {
		return false
	}
	a.objects[key] = struct{}{}
	return true
}
854254
func (s *booleanCompilerVisitor) AcceptCall(v tree.Call) {
	s.err = errors.New("a call was found in an expression - this is likely a programmer error")
}
550298
func (t *precompilationTypeChecker) AcceptAnd(v tree.And) {
	res := either(
		checkPrecompilationRules(v.Left),
		checkPrecompilationRules(v.Right))
	if res != nil {
		t.result = res
	}
}