1// Copyright 2014 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package proptools 16 17import ( 18 "fmt" 19 "reflect" 20 "sort" 21 "strconv" 22 "strings" 23 "text/scanner" 24 25 "github.com/google/blueprint/parser" 26) 27 28const maxUnpackErrors = 10 29 30type UnpackError struct { 31 Err error 32 Pos scanner.Position 33} 34 35func (e *UnpackError) Error() string { 36 return fmt.Sprintf("%s: %s", e.Pos, e.Err) 37} 38 39// packedProperty helps to track properties usage (`used` will be true) 40type packedProperty struct { 41 property *parser.Property 42 used bool 43} 44 45// unpackContext keeps compound names and their values in a map. It is initialized from 46// parsed properties. 47type unpackContext struct { 48 propertyMap map[string]*packedProperty 49 errs []error 50} 51 52// UnpackProperties populates the list of runtime values ("property structs") from the parsed properties. 53// If a property a.b.c has a value, a field with the matching name in each runtime value is initialized 54// from it. See PropertyNameForField for field and property name matching. 55// For instance, if the input contains 56// 57// { foo: "abc", bar: {x: 1},} 58// 59// and a runtime value being has been declared as 60// 61// var v struct { Foo string; Bar int } 62// 63// then v.Foo will be set to "abc" and v.Bar will be set to 1 64// (cf. unpack_test.go for further examples) 65// 66// The type of a receiving field has to match the property type, i.e., a bool/int/string field 67// can be set from a property with bool/int/string value, a struct can be set from a map (only the 68// matching fields are set), and an slice can be set from a list. 69// If a field of a runtime value has been already set prior to the UnpackProperties, the new value 70// is appended to it (see somewhat inappropriately named ExtendBasicType). 71// The same property can initialize fields in multiple runtime values. It is an error if any property 72// value was not used to initialize at least one field. 73func UnpackProperties(properties []*parser.Property, objects ...interface{}) (map[string]*parser.Property, []error) { 74 var unpackContext unpackContext 75 unpackContext.propertyMap = make(map[string]*packedProperty) 76 if !unpackContext.buildPropertyMap("", properties) { 77 return nil, unpackContext.errs 78 } 79 80 for _, obj := range objects { 81 valueObject := reflect.ValueOf(obj) 82 if !isStructPtr(valueObject.Type()) { 83 panic(fmt.Errorf("properties must be *struct, got %s", 84 valueObject.Type())) 85 } 86 unpackContext.unpackToStruct("", valueObject.Elem()) 87 if len(unpackContext.errs) >= maxUnpackErrors { 88 return nil, unpackContext.errs 89 } 90 } 91 92 // Gather property map, and collect any unused properties. 93 // Avoid reporting subproperties of unused properties. 94 result := make(map[string]*parser.Property) 95 var unusedNames []string 96 for name, v := range unpackContext.propertyMap { 97 if v.used { 98 result[name] = v.property 99 } else { 100 unusedNames = append(unusedNames, name) 101 } 102 } 103 if len(unusedNames) == 0 && len(unpackContext.errs) == 0 { 104 return result, nil 105 } 106 return nil, unpackContext.reportUnusedNames(unusedNames) 107} 108 109func (ctx *unpackContext) reportUnusedNames(unusedNames []string) []error { 110 sort.Strings(unusedNames) 111 unusedNames = removeUnnecessaryUnusedNames(unusedNames) 112 var lastReported string 113 for _, name := range unusedNames { 114 // if 'foo' has been reported, ignore 'foo\..*' and 'foo\[.*' 115 if lastReported != "" { 116 trimmed := strings.TrimPrefix(name, lastReported) 117 if trimmed != name && (trimmed[0] == '.' || trimmed[0] == '[') { 118 continue 119 } 120 } 121 ctx.errs = append(ctx.errs, &UnpackError{ 122 fmt.Errorf("unrecognized property %q", name), 123 ctx.propertyMap[name].property.ColonPos}) 124 lastReported = name 125 } 126 return ctx.errs 127} 128 129// When property a.b.c is not used, (also there is no a.* or a.b.* used) 130// "a", "a.b" and "a.b.c" are all in unusedNames. 131// removeUnnecessaryUnusedNames only keeps the last "a.b.c" as the real unused 132// name. 133func removeUnnecessaryUnusedNames(names []string) []string { 134 if len(names) == 0 { 135 return names 136 } 137 var simplifiedNames []string 138 for index, name := range names { 139 if index == len(names)-1 || !strings.HasPrefix(names[index+1], name) { 140 simplifiedNames = append(simplifiedNames, name) 141 } 142 } 143 return simplifiedNames 144} 145 146func (ctx *unpackContext) buildPropertyMap(prefix string, properties []*parser.Property) bool { 147 nOldErrors := len(ctx.errs) 148 for _, property := range properties { 149 name := fieldPath(prefix, property.Name) 150 if first, present := ctx.propertyMap[name]; present { 151 ctx.addError( 152 &UnpackError{fmt.Errorf("property %q already defined", name), property.ColonPos}) 153 if ctx.addError( 154 &UnpackError{fmt.Errorf("<-- previous definition here"), first.property.ColonPos}) { 155 return false 156 } 157 continue 158 } 159 160 ctx.propertyMap[name] = &packedProperty{property, false} 161 switch propValue := property.Value.(type) { 162 case *parser.Map: 163 ctx.buildPropertyMap(name, propValue.Properties) 164 case *parser.List: 165 // If it is a list, unroll it unless its elements are of primitive type 166 // (no further mapping will be needed in that case, so we avoid cluttering 167 // the map). 168 if len(propValue.Values) == 0 { 169 continue 170 } 171 if t := propValue.Values[0].Type(); t == parser.StringType || t == parser.Int64Type || t == parser.BoolType { 172 continue 173 } 174 175 itemProperties := make([]*parser.Property, len(propValue.Values)) 176 for i, expr := range propValue.Values { 177 itemProperties[i] = &parser.Property{ 178 Name: property.Name + "[" + strconv.Itoa(i) + "]", 179 NamePos: property.NamePos, 180 ColonPos: property.ColonPos, 181 Value: expr, 182 } 183 } 184 if !ctx.buildPropertyMap(prefix, itemProperties) { 185 return false 186 } 187 } 188 } 189 190 return len(ctx.errs) == nOldErrors 191} 192 193func fieldPath(prefix, fieldName string) string { 194 if prefix == "" { 195 return fieldName 196 } 197 return prefix + "." + fieldName 198} 199 200func (ctx *unpackContext) addError(e error) bool { 201 ctx.errs = append(ctx.errs, e) 202 return len(ctx.errs) < maxUnpackErrors 203} 204 205func (ctx *unpackContext) unpackToStruct(namePrefix string, structValue reflect.Value) { 206 structType := structValue.Type() 207 208 for i := 0; i < structValue.NumField(); i++ { 209 fieldValue := structValue.Field(i) 210 field := structType.Field(i) 211 212 // In Go 1.7, runtime-created structs are unexported, so it's not 213 // possible to create an exported anonymous field with a generated 214 // type. So workaround this by special-casing "BlueprintEmbed" to 215 // behave like an anonymous field for structure unpacking. 216 if field.Name == "BlueprintEmbed" { 217 field.Name = "" 218 field.Anonymous = true 219 } 220 221 if field.PkgPath != "" { 222 // This is an unexported field, so just skip it. 223 continue 224 } 225 226 propertyName := fieldPath(namePrefix, PropertyNameForField(field.Name)) 227 228 if !fieldValue.CanSet() { 229 panic(fmt.Errorf("field %s is not settable", propertyName)) 230 } 231 232 // Get the property value if it was specified. 233 packedProperty, propertyIsSet := ctx.propertyMap[propertyName] 234 235 origFieldValue := fieldValue 236 237 // To make testing easier we validate the struct field's type regardless 238 // of whether or not the property was specified in the parsed string. 239 // TODO(ccross): we don't validate types inside nil struct pointers 240 // Move type validation to a function that runs on each factory once 241 switch kind := fieldValue.Kind(); kind { 242 case reflect.Bool, reflect.String, reflect.Struct, reflect.Slice: 243 // Do nothing 244 case reflect.Interface: 245 if fieldValue.IsNil() { 246 panic(fmt.Errorf("field %s contains a nil interface", propertyName)) 247 } 248 fieldValue = fieldValue.Elem() 249 elemType := fieldValue.Type() 250 if elemType.Kind() != reflect.Ptr { 251 panic(fmt.Errorf("field %s contains a non-pointer interface", propertyName)) 252 } 253 fallthrough 254 case reflect.Ptr: 255 switch ptrKind := fieldValue.Type().Elem().Kind(); ptrKind { 256 case reflect.Struct: 257 if fieldValue.IsNil() && (propertyIsSet || field.Anonymous) { 258 // Instantiate nil struct pointers 259 // Set into origFieldValue in case it was an interface, in which case 260 // fieldValue points to the unsettable pointer inside the interface 261 fieldValue = reflect.New(fieldValue.Type().Elem()) 262 origFieldValue.Set(fieldValue) 263 } 264 fieldValue = fieldValue.Elem() 265 case reflect.Bool, reflect.Int64, reflect.String: 266 // Nothing 267 default: 268 panic(fmt.Errorf("field %s contains a pointer to %s", propertyName, ptrKind)) 269 } 270 271 case reflect.Int, reflect.Uint: 272 if !HasTag(field, "blueprint", "mutated") { 273 panic(fmt.Errorf(`int field %s must be tagged blueprint:"mutated"`, propertyName)) 274 } 275 276 default: 277 panic(fmt.Errorf("unsupported kind for field %s: %s", propertyName, kind)) 278 } 279 280 if field.Anonymous && isStruct(fieldValue.Type()) { 281 ctx.unpackToStruct(namePrefix, fieldValue) 282 continue 283 } 284 285 if !propertyIsSet { 286 // This property wasn't specified. 287 continue 288 } 289 290 packedProperty.used = true 291 property := packedProperty.property 292 293 if HasTag(field, "blueprint", "mutated") { 294 if !ctx.addError( 295 &UnpackError{ 296 fmt.Errorf("mutated field %s cannot be set in a Blueprint file", propertyName), 297 property.ColonPos, 298 }) { 299 return 300 } 301 continue 302 } 303 304 if isConfigurable(fieldValue.Type()) { 305 // configurableType is the reflect.Type representation of a Configurable[whatever], 306 // while configuredType is the reflect.Type of the "whatever". 307 configurableType := fieldValue.Type() 308 configuredType := fieldValue.Interface().(configurableReflection).configuredType() 309 if unpackedValue, ok := ctx.unpackToConfigurable(propertyName, property, configurableType, configuredType); ok { 310 ExtendBasicType(fieldValue, unpackedValue.Elem(), Append) 311 } 312 if len(ctx.errs) >= maxUnpackErrors { 313 return 314 } 315 } else if isStruct(fieldValue.Type()) { 316 if property.Value.Type() != parser.MapType { 317 ctx.addError(&UnpackError{ 318 fmt.Errorf("can't assign %s value to map property %q", 319 property.Value.Type(), property.Name), 320 property.Value.Pos(), 321 }) 322 continue 323 } 324 ctx.unpackToStruct(propertyName, fieldValue) 325 if len(ctx.errs) >= maxUnpackErrors { 326 return 327 } 328 } else if isSlice(fieldValue.Type()) { 329 if unpackedValue, ok := ctx.unpackToSlice(propertyName, property, fieldValue.Type()); ok { 330 ExtendBasicType(fieldValue, unpackedValue, Append) 331 } 332 if len(ctx.errs) >= maxUnpackErrors { 333 return 334 } 335 } else { 336 unpackedValue, err := propertyToValue(fieldValue.Type(), property) 337 if err != nil && !ctx.addError(err) { 338 return 339 } 340 ExtendBasicType(fieldValue, unpackedValue, Append) 341 } 342 } 343} 344 345// Converts the given property to a pointer to a configurable struct 346func (ctx *unpackContext) unpackToConfigurable(propertyName string, property *parser.Property, configurableType, configuredType reflect.Type) (reflect.Value, bool) { 347 switch v := property.Value.(type) { 348 case *parser.String: 349 if configuredType.Kind() != reflect.String { 350 ctx.addError(&UnpackError{ 351 fmt.Errorf("can't assign string value to configurable %s property %q", 352 configuredType.String(), property.Name), 353 property.Value.Pos(), 354 }) 355 return reflect.New(configurableType), false 356 } 357 var postProcessors [][]postProcessor[string] 358 result := Configurable[string]{ 359 propertyName: property.Name, 360 inner: &configurableInner[string]{ 361 single: singleConfigurable[string]{ 362 cases: []ConfigurableCase[string]{{ 363 value: v, 364 }}, 365 }, 366 }, 367 postProcessors: &postProcessors, 368 } 369 return reflect.ValueOf(&result), true 370 case *parser.Bool: 371 if configuredType.Kind() != reflect.Bool { 372 ctx.addError(&UnpackError{ 373 fmt.Errorf("can't assign bool value to configurable %s property %q", 374 configuredType.String(), property.Name), 375 property.Value.Pos(), 376 }) 377 return reflect.New(configurableType), false 378 } 379 var postProcessors [][]postProcessor[bool] 380 result := Configurable[bool]{ 381 propertyName: property.Name, 382 inner: &configurableInner[bool]{ 383 single: singleConfigurable[bool]{ 384 cases: []ConfigurableCase[bool]{{ 385 value: v, 386 }}, 387 }, 388 }, 389 postProcessors: &postProcessors, 390 } 391 return reflect.ValueOf(&result), true 392 case *parser.Int64: 393 if configuredType.Kind() != reflect.Int64 { 394 ctx.addError(&UnpackError{ 395 fmt.Errorf("can't assign int64 value to configurable %s property %q", 396 configuredType.String(), property.Name), 397 property.Value.Pos(), 398 }) 399 return reflect.New(configurableType), false 400 } 401 var postProcessors [][]postProcessor[int64] 402 result := Configurable[int64]{ 403 propertyName: property.Name, 404 inner: &configurableInner[int64]{ 405 single: singleConfigurable[int64]{ 406 cases: []ConfigurableCase[int64]{{ 407 value: v, 408 }}, 409 }, 410 }, 411 postProcessors: &postProcessors, 412 } 413 return reflect.ValueOf(&result), true 414 case *parser.List: 415 if configuredType.Kind() != reflect.Slice { 416 ctx.addError(&UnpackError{ 417 fmt.Errorf("can't assign list value to configurable %s property %q", 418 configuredType.String(), property.Name), 419 property.Value.Pos(), 420 }) 421 return reflect.New(configurableType), false 422 } 423 switch configuredType.Elem().Kind() { 424 case reflect.String: 425 var value []string 426 if v.Values != nil { 427 value = make([]string, len(v.Values)) 428 itemProperty := &parser.Property{NamePos: property.NamePos, ColonPos: property.ColonPos} 429 for i, expr := range v.Values { 430 itemProperty.Name = propertyName + "[" + strconv.Itoa(i) + "]" 431 itemProperty.Value = expr 432 exprUnpacked, err := propertyToValue(configuredType.Elem(), itemProperty) 433 if err != nil { 434 ctx.addError(err) 435 return reflect.ValueOf(Configurable[[]string]{}), false 436 } 437 value[i] = exprUnpacked.Interface().(string) 438 } 439 } 440 var postProcessors [][]postProcessor[[]string] 441 result := Configurable[[]string]{ 442 propertyName: property.Name, 443 inner: &configurableInner[[]string]{ 444 single: singleConfigurable[[]string]{ 445 cases: []ConfigurableCase[[]string]{{ 446 value: v, 447 }}, 448 }, 449 }, 450 postProcessors: &postProcessors, 451 } 452 return reflect.ValueOf(&result), true 453 default: 454 panic("This should be unreachable because ConfigurableElements only accepts slices of strings") 455 } 456 case *parser.Select: 457 resultPtr := reflect.New(configurableType) 458 result := resultPtr.Elem() 459 conditions := make([]ConfigurableCondition, len(v.Conditions)) 460 for i, cond := range v.Conditions { 461 args := make([]string, len(cond.Args)) 462 for j, arg := range cond.Args { 463 args[j] = arg.Value 464 } 465 conditions[i] = ConfigurableCondition{ 466 functionName: cond.FunctionName, 467 args: args, 468 } 469 } 470 471 configurableCaseType := configurableCaseType(configuredType) 472 cases := reflect.MakeSlice(reflect.SliceOf(configurableCaseType), 0, len(v.Cases)) 473 for _, c := range v.Cases { 474 patterns := make([]ConfigurablePattern, len(c.Patterns)) 475 for i, pat := range c.Patterns { 476 switch pat := pat.Value.(type) { 477 case *parser.String: 478 if pat.Value == "__soong_conditions_default__" { 479 patterns[i].typ = configurablePatternTypeDefault 480 } else if pat.Value == "__soong_conditions_any__" { 481 patterns[i].typ = configurablePatternTypeAny 482 } else { 483 patterns[i].typ = configurablePatternTypeString 484 patterns[i].stringValue = pat.Value 485 } 486 case *parser.Bool: 487 patterns[i].typ = configurablePatternTypeBool 488 patterns[i].boolValue = pat.Value 489 case *parser.Int64: 490 patterns[i].typ = configurablePatternTypeInt64 491 patterns[i].int64Value = pat.Value 492 default: 493 panic("unimplemented") 494 } 495 patterns[i].binding = pat.Binding.Name 496 } 497 498 case_ := reflect.New(configurableCaseType) 499 case_.Interface().(configurableCaseReflection).initialize(patterns, c.Value) 500 cases = reflect.Append(cases, case_.Elem()) 501 } 502 resultPtr.Interface().(configurablePtrReflection).initialize( 503 v.Scope, 504 property.Name, 505 conditions, 506 cases.Interface(), 507 ) 508 if v.Append != nil { 509 p := &parser.Property{ 510 Name: property.Name, 511 NamePos: property.NamePos, 512 Value: v.Append, 513 } 514 val, ok := ctx.unpackToConfigurable(propertyName, p, configurableType, configuredType) 515 if !ok { 516 return reflect.New(configurableType), false 517 } 518 result.Interface().(configurableReflection).setAppend(val.Elem().Interface(), false, false) 519 } 520 return resultPtr, true 521 default: 522 ctx.addError(&UnpackError{ 523 fmt.Errorf("can't assign %s value to configurable %s property %q", 524 property.Value.Type(), configuredType.String(), property.Name), 525 property.Value.Pos(), 526 }) 527 return reflect.New(configurableType), false 528 } 529} 530 531// If the given property is a select, returns an error saying that you can't assign a select to 532// a non-configurable property. Otherwise returns nil. 533func selectOnNonConfigurablePropertyError(property *parser.Property) error { 534 if _, ok := property.Value.(*parser.Select); !ok { 535 return nil 536 } 537 538 return &UnpackError{ 539 fmt.Errorf("can't assign select statement to non-configurable property %q. This requires a small soong change to enable in most cases, please file a go/soong-bug if you'd like to use a select statement here", 540 property.Name), 541 property.Value.Pos(), 542 } 543} 544 545// unpackSlice creates a value of a given slice or pointer to slice type from the property, 546// which should be a list 547func (ctx *unpackContext) unpackToSlice( 548 sliceName string, property *parser.Property, sliceType reflect.Type) (reflect.Value, bool) { 549 if sliceType.Kind() == reflect.Pointer { 550 sliceType = sliceType.Elem() 551 result := reflect.New(sliceType) 552 slice, ok := ctx.unpackToSliceInner(sliceName, property, sliceType) 553 if !ok { 554 return result, ok 555 } 556 result.Elem().Set(slice) 557 return result, true 558 } 559 return ctx.unpackToSliceInner(sliceName, property, sliceType) 560} 561 562// unpackToSliceInner creates a value of a given slice type from the property, 563// which should be a list. It doesn't support pointers to slice types like unpackToSlice 564// does. 565func (ctx *unpackContext) unpackToSliceInner( 566 sliceName string, property *parser.Property, sliceType reflect.Type) (reflect.Value, bool) { 567 propValueAsList, ok := property.Value.(*parser.List) 568 if !ok { 569 if err := selectOnNonConfigurablePropertyError(property); err != nil { 570 ctx.addError(err) 571 } else { 572 ctx.addError(&UnpackError{ 573 fmt.Errorf("can't assign %s value to list property %q", 574 property.Value.Type(), property.Name), 575 property.Value.Pos(), 576 }) 577 } 578 return reflect.MakeSlice(sliceType, 0, 0), false 579 } 580 exprs := propValueAsList.Values 581 value := reflect.MakeSlice(sliceType, 0, len(exprs)) 582 if len(exprs) == 0 { 583 return value, true 584 } 585 586 // The function to construct an item value depends on the type of list elements. 587 getItemFunc := func(property *parser.Property, t reflect.Type) (reflect.Value, bool) { 588 switch property.Value.(type) { 589 case *parser.Bool, *parser.String, *parser.Int64: 590 value, err := propertyToValue(t, property) 591 if err != nil { 592 ctx.addError(err) 593 return value, false 594 } 595 return value, true 596 case *parser.List: 597 return ctx.unpackToSlice(property.Name, property, t) 598 case *parser.Map: 599 itemValue := reflect.New(t).Elem() 600 ctx.unpackToStruct(property.Name, itemValue) 601 return itemValue, true 602 default: 603 panic(fmt.Errorf("bizarre property expression type: %v, %#v", property.Value.Type(), property.Value)) 604 } 605 } 606 607 itemProperty := &parser.Property{NamePos: property.NamePos, ColonPos: property.ColonPos} 608 elemType := sliceType.Elem() 609 isPtr := elemType.Kind() == reflect.Ptr 610 611 for i, expr := range exprs { 612 itemProperty.Name = sliceName + "[" + strconv.Itoa(i) + "]" 613 itemProperty.Value = expr 614 if packedProperty, ok := ctx.propertyMap[itemProperty.Name]; ok { 615 packedProperty.used = true 616 } 617 if isPtr { 618 if itemValue, ok := getItemFunc(itemProperty, elemType.Elem()); ok { 619 ptrValue := reflect.New(itemValue.Type()) 620 ptrValue.Elem().Set(itemValue) 621 value = reflect.Append(value, ptrValue) 622 } 623 } else { 624 if itemValue, ok := getItemFunc(itemProperty, elemType); ok { 625 value = reflect.Append(value, itemValue) 626 } 627 } 628 } 629 return value, true 630} 631 632// propertyToValue creates a value of a given value type from the property. 633func propertyToValue(typ reflect.Type, property *parser.Property) (reflect.Value, error) { 634 var value reflect.Value 635 var baseType reflect.Type 636 isPtr := typ.Kind() == reflect.Ptr 637 if isPtr { 638 baseType = typ.Elem() 639 } else { 640 baseType = typ 641 } 642 643 switch kind := baseType.Kind(); kind { 644 case reflect.Bool: 645 b, ok := property.Value.(*parser.Bool) 646 if !ok { 647 if err := selectOnNonConfigurablePropertyError(property); err != nil { 648 return value, err 649 } else { 650 return value, &UnpackError{ 651 fmt.Errorf("can't assign %s value to bool property %q", 652 property.Value.Type(), property.Name), 653 property.Value.Pos(), 654 } 655 } 656 } 657 value = reflect.ValueOf(b.Value) 658 659 case reflect.Int64: 660 b, ok := property.Value.(*parser.Int64) 661 if !ok { 662 return value, &UnpackError{ 663 fmt.Errorf("can't assign %s value to int64 property %q", 664 property.Value.Type(), property.Name), 665 property.Value.Pos(), 666 } 667 } 668 value = reflect.ValueOf(b.Value) 669 670 case reflect.String: 671 s, ok := property.Value.(*parser.String) 672 if !ok { 673 if err := selectOnNonConfigurablePropertyError(property); err != nil { 674 return value, err 675 } else { 676 return value, &UnpackError{ 677 fmt.Errorf("can't assign %s value to string property %q", 678 property.Value.Type(), property.Name), 679 property.Value.Pos(), 680 } 681 } 682 } 683 value = reflect.ValueOf(s.Value) 684 685 default: 686 return value, &UnpackError{ 687 fmt.Errorf("cannot assign %s value %s to %s property %s", property.Value.Type(), property.Value, kind, typ), 688 property.NamePos} 689 } 690 691 if isPtr { 692 ptrValue := reflect.New(value.Type()) 693 ptrValue.Elem().Set(value) 694 return ptrValue, nil 695 } 696 return value, nil 697} 698