// Realizes copies the fields from desired into p. It assumes that the fields in
// desired are not modified after this function is called.
491605
func (p *EndpointPolicy) Realizes(desired *EndpointPolicy) {
	if p == nil {
		p = NewEndpointPolicy()
	}

	p.SelectorPolicy.Realizes(desired.SelectorPolicy)
	p.DeniedEgressIdentities = desired.DeniedEgressIdentities
	p.DeniedIngressIdentities = desired.DeniedIngressIdentities
}
680823
func (s *arithmeticSimplifier) AcceptArithmetic(a tree.Arithmetic) {
	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.PLUS:
			s.Result = tree.NumericLiteral{pl + pr}
			return
		case tree.MINUS:
			s.Result = tree.NumericLiteral{pl - pr}
			return
		case tree.MULT:
			s.Result = tree.NumericLiteral{pl * pr}
			return
		case tree.DIV:
			s.Result = tree.NumericLiteral{pl / pr}
			return
		case tree.MOD:
			s.Result = tree.NumericLiteral{pl % pr}
			return
		case tree.BINAND:
			s.Result = tree.NumericLiteral{pl & pr}
			return
		case tree.BINOR:
			s.Result = tree.NumericLiteral{pl | pr}
			return
		case tree.BINXOR:
			s.Result = tree.NumericLiteral{pl ^ pr}
			return
		case tree.LSH:
			s.Result = tree.NumericLiteral{pl << pr}
			return
		case tree.RSH:
			s.Result = tree.NumericLiteral{pl >> pr}
			return
		}
	}
	s.Result = tree.Arithmetic{Op: a.Op, Left: l, Right: r}
}
1171436
func (n *Conditional) Accept(v Visitor) Node {
	n.CondExpr = n.CondExpr.Accept(v)
	n.TrueExpr = n.TrueExpr.Accept(v)
	n.FalseExpr = n.FalseExpr.Accept(v)

	return v(n)
}
1301471
func (accept AcceptSlice) Accepts(ctype string) bool {
	t, err := accept.Negotiate(ctype)
	if t == "" || err != nil {
		return false
	}
	return true
}
1372513
func (r *ResponseDefinition) Finalize() {
	if r.Type == nil {
		return
	}
	if r.MediaType != "" && r.MediaType != "text/plain" {
		return
	}
	mt, ok := r.Type.(*MediaTypeDefinition)
	if !ok {
		return
	}
	r.MediaType = mt.Identifier
}
1128882
func (c *StringMatchCondition) Fulfills(value interface{}, _ *Request) bool {
	s, ok := value.(string)

	matches, _ := regexp.MatchString(c.Matches, s)

	return ok && matches
}
158965
func (in *IncomingSession) Accept() Endpoint {
	return in.accept(func() Endpoint {
		return newSession(in.h.connection, in.pSession, IncomingCapacity(in.incomingCapacity), OutgoingWindow(in.outgoingWindow))
	})
}
113357
func (n *ColumnDef) Accept(v Visitor) (Node, bool) {
	newNode, skipChildren := v.Enter(n)
	if skipChildren {
		return v.Leave(newNode)
	}
	n = newNode.(*ColumnDef)
	node, ok := n.Name.Accept(v)
	if !ok {
		return n, false
	}
	n.Name = node.(*ColumnName)
	for i, val := range n.Options {
		node, ok := val.Accept(v)
		if !ok {
			return n, false
		}
		n.Options[i] = node.(*ColumnOption)
	}
	return v.Leave(n)
}
905777
func accepts(a, ctype string) (q float64) {
	if a == ctype || a == "*/*" || a == "" {
		// bail out in some common cases
		return 1
	}
	cGroup, cType := split(ctype, "/")
	for _, field := range strings.Split(a, ",") {
		found, match := false, false
		for i, token := range strings.Split(field, ";") {
			if i == 0 {
				// token is "type/subtype", "type/*" or "*/*"
				aGroup, aType := split(token, "/")
				if cType == aType || aType == "*" {
					if (aGroup == "*" && aType == "*") || cGroup == aGroup {
						// token matches, continue to look for a q value
						found = true
						continue
					}
				}
				break
			}
			// token is "key=value"
			k, v := split(token, "=")
			if k != "q" {
				continue
			}
			// k is "q"
			f, err := strconv.ParseFloat(v, 64)
			if err != nil {
				break
			}
			if q < f {
				q = f
			}
			match = true
			break
		}
		if found && !match {
			q = 1
			break
		}
	}
	return
}
95792
func (c *StringEqualCondition) Fulfills(value interface{}, _ *Request) bool {
	s, ok := value.(string)

	return ok && s == c.Equals
}
961024
func (fields FieldTransfer) To(target interface{}) {
	for k, v := range fields {
		val := reflect.ValueOf(target).Elem().FieldByNameFunc(func(n string) bool {
			return strings.ToLower(n) == strings.ToLower(k)
		})
		if val.IsValid() && val.CanSet() {
			val.SetString(v)
		}
	}
}
806186
func (c *Adaptor) Finalize() (err error) {
	c.mutex.Lock()
	defer c.mutex.Unlock()

	for _, pin := range c.digitalPins {
		if pin != nil {
			if e := pin.Unexport(); e != nil {
				err = multierror.Append(err, e)
			}
		}
	}
	for _, pin := range c.pwmPins {
		if pin != nil {
			if errs := pin.Enable(false); errs != nil {
				err = multierror.Append(err, errs)
			}
			if errs := pin.Unexport(); errs != nil {
				err = multierror.Append(err, errs)
			}
		}
	}
	for _, bus := range c.i2cBuses {
		if bus != nil {
			if e := bus.Close(); e != nil {
				err = multierror.Append(err, e)
			}
		}
	}
	return
}
1365771
func (p *File_Template_Parameter) Accepts(v *Value) error {
	if v.IsNull() {
		if !p.Nullable {
			return errors.New("not nullable")
		}
	} else if err := p.Schema.Accepts(v); err != nil {
		return err
	} else if err := v.Check(p.Schema); err != nil {
		return err
	}
	return nil
}
742159
func (d *decodeState) scanWhile(op int) int {
	var newOp int
	for {
		if d.off >= len(d.data) {
			newOp = d.scan.EOF()
			d.off = len(d.data) + 1 // mark processed EOF with len+1
		} else {
			c := int(d.data[d.off])
			d.off++
			newOp = d.scan.Step(&d.scan, c)
		}
		if newOp != op {
			break
		}
	}
	return newOp
}
1023492
func (n *UnaryOperationExpr) Accept(v Visitor) (Node, bool) {
	newNode, skipChildren := v.Enter(n)
	if skipChildren {
		return v.Leave(newNode)
	}
	n = newNode.(*UnaryOperationExpr)
	node, ok := n.V.Accept(v)
	if !ok {
		return n, false
	}
	n.V = node.(ExprNode)
	return v.Leave(n)
}
896956
func (aa Acceptors) Accept(from interface{}) bool {
	for _, a := range aa {
		if !a.Accept(from) {
			return false
		}
	}
	return true
}
281033
func (c *ResourceContainsCondition) Fulfills(value interface{}, r *Request) bool {

	filter, ok := value.(map[string]interface{})
	if !ok {
		return false
	}

	valueString, ok := filter["value"].(string)
	if !ok || len(valueString) < 1 {
		return false
	}

	//If no delimiter provided default to "equals" check
	delimiterString, ok := filter["delimiter"].(string)
	if !ok || len(delimiterString) < 1 {
		delimiterString = ""
	}

	// Append delimiter to strings to prevent delim+1 being interpreted as delim+10 being present
	filterValue := delimiterString + valueString + delimiterString
	resourceString := delimiterString + r.Resource + delimiterString

	matches := strings.Contains(resourceString, filterValue)
	return matches

}