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

Method IdentifierNode

compiler/compiler.go:300–330  ·  view source on GitHub ↗
(node *ast.IdentifierNode)

Source from the content-addressed store, hash-verified

298}
299
300func (c *compiler) IdentifierNode(node *ast.IdentifierNode) {
301 if index, ok := c.lookupVariable(node.Value); ok {
302 c.emit(OpLoadVar, index)
303 return
304 }
305 if node.Value == "$env" {
306 c.emit(OpLoadEnv)
307 return
308 }
309
310 var env Nature
311 if c.config != nil {
312 env = c.config.Env
313 }
314
315 if env.IsFastMap() {
316 c.emit(OpLoadFast, c.addConstant(node.Value))
317 } else if ok, index, name := checker.FieldIndex(c.ntCache, env, node); ok {
318 c.emit(OpLoadField, c.addConstant(&runtime.Field{
319 Index: index,
320 Path: []string{name},
321 }))
322 } else if ok, index, name := checker.MethodIndex(c.ntCache, env, node); ok {
323 c.emit(OpLoadMethod, c.addConstant(&runtime.Method{
324 Name: name,
325 Index: index,
326 }))
327 } else {
328 c.emit(OpLoadConst, c.addConstant(node.Value))
329 }
330}
331
332func (c *compiler) IntegerNode(node *ast.IntegerNode) {
333 t := node.Type()

Callers 1

compileMethod · 0.95

Calls 6

lookupVariableMethod · 0.95
emitMethod · 0.95
IsFastMapMethod · 0.95
addConstantMethod · 0.95
FieldIndexFunction · 0.92
MethodIndexFunction · 0.92

Tested by

no test coverage detected