MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / Call

Method Call

pkg/filter/ql/function.go:160–286  ·  view source on GitHub ↗
(args []interface{})

Source from the content-addressed store, hash-verified

158type Foreach struct{}
159
160func (f *Foreach) Call(args []interface{}) (interface{}, bool) {
161 if len(args) < 3 {
162 return false, false
163 }
164
165 s := args[0] // iterable (slice or map)
166 if s == nil {
167 return false, false
168 }
169
170 v, ok := args[1].(*BareBoundVariableLiteral) // item (variable)
171 if !ok {
172 return false, false
173 }
174
175 e := args[2] // predicate (expression)
176 if e == nil {
177 return false, false
178 }
179
180 var valuer = MapValuer{}
181 if len(args) > 3 { // optional predicate captures
182 for i := 3; i < len(args); i++ {
183 m, ok := args[i].(MapValuer)
184 if !ok {
185 continue
186 }
187 maps.Copy(valuer, m)
188 }
189 }
190
191 segments := make([]*BoundSegmentLiteral, 0)
192
193 // obtain bound segments used in expression
194 var useCallValuer bool
195 walk := func(n Node) {
196 switch exp := n.(type) {
197 case *BoundSegmentLiteral:
198 segments = append(segments, exp)
199 case *Function:
200 useCallValuer = true
201 }
202 }
203
204 switch expr := e.(type) {
205 case *BinaryExpr:
206 WalkFunc(expr, walk)
207 case *NotExpr:
208 WalkFunc(expr, walk)
209 }
210
211 switch elems := s.(type) {
212 case []string:
213 for _, elem := range elems {
214 if f.evalExpr(e, useCallValuer, f.stringMapValuer(v, elem), valuer) {
215 return true, true
216 }
217 }

Callers

nothing calls this directly

Calls 13

evalExprMethod · 0.95
stringMapValuerMethod · 0.95
procMapValuerMethod · 0.95
moduleMapValuerMethod · 0.95
threadMapValuerMethod · 0.95
mmapMapValuerMethod · 0.95
sectionMapValuerMethod · 0.95
callstackMapValuerMethod · 0.95
WalkFuncFunction · 0.85
CopyMethod · 0.80
IsEmptyMethod · 0.80
FrameAtMethod · 0.80

Tested by

no test coverage detected