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

Method addConstant

compiler/compiler.go:141–167  ·  view source on GitHub ↗
(constant any)

Source from the content-addressed store, hash-verified

139}
140
141func (c *compiler) addConstant(constant any) int {
142 indexable := true
143 hash := constant
144 switch reflect.TypeOf(constant).Kind() {
145 case reflect.Slice, reflect.Map, reflect.Struct, reflect.Func:
146 indexable = false
147 }
148 if field, ok := constant.(*runtime.Field); ok {
149 indexable = true
150 hash = fmt.Sprintf("%v", field)
151 }
152 if method, ok := constant.(*runtime.Method); ok {
153 indexable = true
154 hash = fmt.Sprintf("%v", method)
155 }
156 if indexable {
157 if p, ok := c.constantsIndex[hash]; ok {
158 return p
159 }
160 }
161 c.constants = append(c.constants, constant)
162 p := len(c.constants) - 1
163 if indexable {
164 c.constantsIndex[hash] = p
165 }
166 return p
167}
168
169func (c *compiler) addVariable(name string) int {
170 c.variables++

Callers 6

emitPushMethod · 0.95
compileMethod · 0.95
IdentifierNodeMethod · 0.95
BinaryNodeMethod · 0.95
MemberNodeMethod · 0.95
BuiltinNodeMethod · 0.95

Calls 1

SprintfMethod · 0.80

Tested by

no test coverage detected