// Evaluate the expression.
323595
func (e *booleanNode) Evaluate(r table.Row) (bool, error) {
	// Binary evaluation
	eval := func(binary bool) (bool, bool, error) {
		var (
			eL, eR     bool
			errL, errR error
		)
		if !e.lS {
			return false, false, fmt.Errorf("boolean operations require a left operator; found (%q, %q) instead", e.lE, e.rE)
		}
		eL, errL = e.lE.Evaluate(r)
		if errL != nil {
			return false, false, errL
		}
		if binary {
			if !e.rS {
				return false, false, fmt.Errorf("boolean operations require a left operator; found (%q, %q) instead", e.lE, e.rE)
			}
			eR, errR = e.rE.Evaluate(r)
			if errR != nil {
				return false, false, errR
			}
		}
		return eL, eR, nil
	}

	switch e.op {
	case AND:
		eL, eR, err := eval(true)
		if err != nil {
			return false, err
		}
		return eL && eR, nil
	case OR:
		eL, eR, err := eval(true)
		if err != nil {
			return false, err
		}
		return eL || eR, nil
	case NOT:
		eL, _, err := eval(false)
		if err != nil {
			return false, err
		}
		return !eL, nil
	default:
		return false, fmt.Errorf("boolean evaluation require a boolen operation; found %q instead", e.op)
	}
}
707816
func (i *DefaultInterpreter) Execute(
	expression string,
	ctx *Context) (interface{}, error) {
	funcs := template.FuncMap{}
	for k, v := range i.Funcs {
		funcs[k] = v
	}
	var res interface{}
	resultEvaluated := false
	funcs["set"] = func(r interface{}) interface{} {
		res = r
		resultEvaluated = true
		return r
	}
	funcs["eval"] = func(intrpr, expr string) (interface{}, error) {
		return ctx.EvalExpr(intrpr, expr, ctx)
	}
	templName := fmt.Sprintf("<<%s>>", ctx.LongName)
	left := i.LeftDelim
	right := i.RightDelim
	if left == "" {
		left = "{{"
	}
	if right == "" {
		right = "}}"
	}
	if i.AutoEnclose &&
		!(strings.HasPrefix(expression, left) &&
			strings.HasSuffix(expression, right)) {
		expression = fmt.Sprintf("%s%s%s", left, expression, right)
	}
	t, err := template.
		New(templName).
		Delims(left, right).
		Funcs(funcs).
		Parse(expression)
	if err != nil {
		return nil, err
	}
	var buf bytes.Buffer
	err = t.Execute(&buf, ctx)
	if err != nil {
		return nil, err
	}
	if resultEvaluated {
		return res, nil
	}
	return buf.String(), nil
}
359413
func evaluate(node ast.Node, ext vmExtMap, tla vmExtMap, nativeFuncs map[string]*NativeFunction,
	maxStack int, importer Importer, stringOutputMode bool) (string, error) {

	i, err := buildInterpreter(ext, nativeFuncs, maxStack, importer)
	if err != nil {
		return "", err
	}

	result, manifestationTrace, err := evaluateAux(i, node, tla)
	if err != nil {
		return "", err
	}

	var buf bytes.Buffer
	if stringOutputMode {
		err = i.manifestString(&buf, manifestationTrace, result)
	} else {
		err = i.manifestAndSerializeJSON(&buf, manifestationTrace, result, true, "")
	}
	if err != nil {
		return "", err
	}
	buf.WriteString("\n")
	return buf.String(), nil
}
1089969
func Evaluate(predictedTrees, goldTrees []*lingo.Dependency) Performance {
	if len(predictedTrees) != len(goldTrees) {
		panic(fmt.Sprintf("%d predicted trees; %d gold trees. Unable to compare", len(predictedTrees), len(goldTrees)))
	}

	var correctLabels, correctHeads, correctTrees, correctRoot, sumArcs float64
	var check int

	for i, tr := range predictedTrees {
		gTr := goldTrees[i]

		if len(tr.AnnotatedSentence) != len(gTr.AnnotatedSentence) {
			sumArcs += float64(gTr.N())

			// log.Printf("WARNING: %q and %q do not have the same length", tr, gTr)
			continue
		}

		var nCorrectHead int
		for j, a := range tr.AnnotatedSentence[1:] {
			b := gTr.AnnotatedSentence[j+1]
			if a.HeadID() == b.HeadID() {
				correctHeads++
				nCorrectHead++
			}

			if a.DependencyType == b.DependencyType {
				correctLabels++
			}
			sumArcs++
		}
		if nCorrectHead == gTr.N() {
			correctTrees++
		}
		if tr.Root() == gTr.Root() {
			correctRoot++
		}

		// check 5 per iteration
		if check < 5 {
			logf("predictedHeads: \n%v\n%v\n", tr.Heads(), gTr.Heads())
			logf("Ns: %v | %v || Correct: %v", tr.N(), gTr.N(), nCorrectHead)
			check++
		}
	}

	uas := correctHeads / sumArcs
	las := correctLabels / sumArcs
	uem := correctTrees / float64(len(predictedTrees))
	roo := correctRoot / float64(len(predictedTrees))

	return Performance{UAS: uas, LAS: las, UEM: uem, Root: roo}
}
426980
func expression(res ...*regexp.Regexp) *regexp.Regexp {
	var s string
	for _, re := range res {
		s += re.String()
	}

	return match(s)
}
92922
func (r *Rego) Eval(ctx context.Context) (ResultSet, error) {
	var err error
	if r.txn == nil {
		r.txn, err = r.store.NewTransaction(ctx)
		if err != nil {
			return nil, err
		}
		defer r.store.Abort(ctx, r.txn)
	}

	pq, err := r.PrepareForEval(ctx)
	if err != nil {
		return nil, err
	}

	return pq.Eval(ctx)
}
1162172
func (f stringNotLikeFunc) evaluate(values map[string][]string) bool {
	return !f.stringLikeFunc.evaluate(values)
}
143149
func (c *ConfigParser) evaluateExpressions(m map[string]interface{}, seenKeys []string, testOnly bool) error {
	for k, ei := range m {
		thisPath := append(seenKeys, k)
		switch subval := ei.(type) {
		case string, bool, float64, nil:
			continue
		case []interface{}:
			if len(subval) == 0 {
				continue
			}
			evaled, err := c.evalValue(subval)
			if err != nil {
				return fmt.Errorf("%s: value error %v", strings.Join(thisPath, "."), err)
			}
			if !testOnly {
				m[k] = evaled
			}
		case map[string]interface{}:
			if err := c.evaluateExpressions(subval, thisPath, testOnly); err != nil {
				return err
			}
		default:
			return fmt.Errorf("%s: unhandled type %T", strings.Join(thisPath, "."), ei)
		}
	}
	return nil
}
883724
func eval(expr ast.Node, context Context) (interface{}, error) {
	//fmt.Println(reflect.TypeOf(expr), time.Now().UnixNano()/int64(10000), expr)
	switch expr.(type) {
	/*
		case *ast.ArrayType:
			return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		case *ast.AssignStmt:
			return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		case *ast.BadDecl:
			return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		case *ast.BadExpr:
			return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		case *ast.BadStmt:
			return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
	*/
	case *constNodeBinaryExpr:
		return expr.(*constNodeBinaryExpr).value, nil
	case *constNodeUnaryExpr:
		return expr.(*constNodeUnaryExpr).value, nil
	case *constNodeBasicLit:
		return expr.(*constNodeBasicLit).value, nil
	case *constNodeIdent:
		return expr.(*constNodeIdent).value, nil
	case *constNodeParenExpr:
		return expr.(*constNodeParenExpr).value, nil
	case *ast.BasicLit:
		return evalBasicLit(expr.(*ast.BasicLit), context)
	case *ast.BinaryExpr:
		return evalBinaryExpr(expr.(*ast.BinaryExpr), context)
		/*
			case *ast.BlockStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.BranchStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.CallExpr:
		return evalCallExpr(expr.(*ast.CallExpr), context)
		/*
			case *ast.CaseClause:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.ChanType:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.CommClause:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.Comment:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.CommentGroup:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.CompositeLit:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.DeclStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.DeferStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.Ellipsis:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.EmptyStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.Field:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.FieldList:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.ForStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.FuncDecl:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.FuncLit:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.FuncType:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.GenDecl:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.GoStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.Ident:
		return evalIdent(expr.(*ast.Ident), context)
		/*
			case *ast.IfStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.ImportSpec:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.IncDecStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.IndexExpr:
		return evalIndexExpr(expr.(*ast.IndexExpr), context)
		/*
			case *ast.InterfaceType:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.KeyValueExpr:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.LabeledStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.MapType:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.Package:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.ParenExpr:
		return evalParenExpr(expr.(*ast.ParenExpr), context)
		/*
			case *ast.RangeStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.ReturnStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.SelectStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.SelectorExpr:
		return evalSelectorExpr(expr.(*ast.SelectorExpr), context)
		/*
			case *ast.SendStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.SliceExpr:
		return evalSliceExpr(expr.(*ast.SliceExpr), context)
	case *ast.StarExpr:
		return evalStarExpr(expr.(*ast.StarExpr), context)
		/*
			case *ast.StructType:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.SwitchStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.TypeAssertExpr:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.TypeSpec:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.TypeSwitchStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.UnaryExpr:
		return evalUnaryExpr(expr.(*ast.UnaryExpr), context)
		/*
			case *ast.ValueSpec:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	default:
		return nilInterf, fmt.Errorf("Default %s not suported", reflect.TypeOf(expr))
	}
}
655660
func (e *Expr) Eval(context interface{}) (val interface{}, err error) {

	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("Eval paniked. %s", r)
		}
	}()

	//create context for evaluation
	ctxt := createContext(context)

	//evaluate the prepared sentence
	val, err = eval(e.expr, ctxt)

	return val, err
}
184823
func (m *MockPolicy) Evaluate(signatureSet []*common.SignedData) error {
	fmt.Printf("Evaluate [%s], [% x], [% x]\n", string(signatureSet[0].Identity), string(signatureSet[0].Data), string(signatureSet[0].Signature))
	identity, err := m.Deserializer.DeserializeIdentity(signatureSet[0].Identity)
	if err != nil {
		return err
	}

	return identity.Verify(signatureSet[0].Data, signatureSet[0].Signature)
}
298582
func evalExpr(expr influxql.Expr, m Valuer) interface{} {
	if expr == nil {
		return nil
	}

	switch expr := expr.(type) {
	case *influxql.BinaryExpr:
		return evalBinaryExpr(expr, m)
	case *influxql.BooleanLiteral:
		return expr.Val
	case *influxql.IntegerLiteral:
		return expr.Val
	case *influxql.UnsignedLiteral:
		return expr.Val
	case *influxql.NumberLiteral:
		return expr.Val
	case *influxql.ParenExpr:
		return evalExpr(expr.Expr, m)
	case *influxql.RegexLiteral:
		return expr.Val
	case *influxql.StringLiteral:
		return expr.Val
	case *influxql.VarRef:
		v, _ := m.Value(expr.Val)
		return v
	default:
		return nil
	}
}
126213
func (c *PrefixCondition) Evaluate(path *Path, _ *PolicyOptions) bool {
	var key string
	var masklen uint8
	keyf := func(ip net.IP, ones int) string {
		var buffer bytes.Buffer
		for i := 0; i < len(ip) && i < ones; i++ {
			buffer.WriteString(fmt.Sprintf("%08b", ip[i]))
		}
		return buffer.String()[:ones]
	}
	family := path.GetRouteFamily()
	switch family {
	case bgp.RF_IPv4_UC:
		masklen = path.GetNlri().(*bgp.IPAddrPrefix).Length
		key = keyf(path.GetNlri().(*bgp.IPAddrPrefix).Prefix, int(masklen))
	case bgp.RF_IPv6_UC:
		masklen = path.GetNlri().(*bgp.IPv6AddrPrefix).Length
		key = keyf(path.GetNlri().(*bgp.IPv6AddrPrefix).Prefix, int(masklen))
	default:
		return false
	}
	if family != c.set.family {
		return false
	}

	result := false
	_, ps, ok := c.set.tree.LongestPrefix(key)
	if ok {
		for _, p := range ps.([]*Prefix) {
			if p.MasklengthRangeMin <= masklen && masklen <= p.MasklengthRangeMax {
				result = true
				break
			}
		}
	}

	if c.option == MATCH_OPTION_INVERT {
		result = !result
	}

	return result
}
769610
func Eval(expr Expr, m map[string]interface{}) interface{} {
	eval := ValuerEval{Valuer: MapValuer(m)}
	return eval.Eval(expr)
}
1071426
func Eval(s string, mapping func(string) string) (string, error) {
	t, err := Parse(s)
	if err != nil {
		return s, err
	}
	return t.Execute(mapping)
}
176861
func (functions Functions) Evaluate(values map[string][]string) bool {
	for _, f := range functions {
		if !f.evaluate(values) {
			return false
		}
	}

	return true
}
327982
func Expr(expression string, args ...interface{}) *expr {
	return &expr{expr: expression, args: args}
}