MCPcopy
hub / github.com/expr-lang/expr / compile

Method compile

compiler/compiler.go:216–294  ·  view source on GitHub ↗
(node ast.Node)

Source from the content-addressed store, hash-verified

214}
215
216func (c *compiler) compile(node ast.Node) {
217 c.nodes = append(c.nodes, node)
218 defer func() {
219 c.nodes = c.nodes[:len(c.nodes)-1]
220 }()
221
222 if c.config != nil && c.config.Profile {
223 span := &Span{
224 Name: reflect.TypeOf(node).String(),
225 Expression: node.String(),
226 }
227 if len(c.spans) > 0 {
228 prev := c.spans[len(c.spans)-1]
229 prev.Children = append(prev.Children, span)
230 }
231 c.spans = append(c.spans, span)
232 defer func() {
233 if len(c.spans) > 1 {
234 c.spans = c.spans[:len(c.spans)-1]
235 }
236 }()
237
238 c.emit(OpProfileStart, c.addConstant(span))
239 defer func() {
240 c.emit(OpProfileEnd, c.addConstant(span))
241 }()
242 }
243
244 switch n := node.(type) {
245 case *ast.NilNode:
246 c.NilNode(n)
247 case *ast.IdentifierNode:
248 c.IdentifierNode(n)
249 case *ast.IntegerNode:
250 c.IntegerNode(n)
251 case *ast.FloatNode:
252 c.FloatNode(n)
253 case *ast.BoolNode:
254 c.BoolNode(n)
255 case *ast.StringNode:
256 c.StringNode(n)
257 case *ast.BytesNode:
258 c.BytesNode(n)
259 case *ast.ConstantNode:
260 c.ConstantNode(n)
261 case *ast.UnaryNode:
262 c.UnaryNode(n)
263 case *ast.BinaryNode:
264 c.BinaryNode(n)
265 case *ast.ChainNode:
266 c.ChainNode(n)
267 case *ast.MemberNode:
268 c.MemberNode(n)
269 case *ast.SliceNode:
270 c.SliceNode(n)
271 case *ast.CallNode:
272 c.CallNode(n)
273 case *ast.BuiltinNode:

Callers 15

CompileFunction · 0.95
UnaryNodeMethod · 0.95
BinaryNodeMethod · 0.95
equalBinaryNodeMethod · 0.95
ChainNodeMethod · 0.95
MemberNodeMethod · 0.95
SliceNodeMethod · 0.95
CallNodeMethod · 0.95
BuiltinNodeMethod · 0.95
PredicateNodeMethod · 0.95
SequenceNodeMethod · 0.95

Calls 15

emitMethod · 0.95
addConstantMethod · 0.95
NilNodeMethod · 0.95
IdentifierNodeMethod · 0.95
IntegerNodeMethod · 0.95
FloatNodeMethod · 0.95
BoolNodeMethod · 0.95
StringNodeMethod · 0.95
BytesNodeMethod · 0.95
ConstantNodeMethod · 0.95
UnaryNodeMethod · 0.95
BinaryNodeMethod · 0.95

Tested by

no test coverage detected