Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: mojom/mojom_tool/serialization/serialization.go

Issue 1933563002: Mojom frontend: Start populating |resolved_concrete_value| field in mojom_types.mojom (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Grammar fix. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package serialization 5 package serialization
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "compress/gzip" 9 "compress/gzip"
10 "encoding/base64" 10 "encoding/base64"
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 panic(fmt.Sprintf("Unexpected UserDefinedValue type %T", v)) 421 panic(fmt.Sprintf("Unexpected UserDefinedValue type %T", v))
422 422
423 } 423 }
424 } 424 }
425 425
426 func translateUserDefinedConstant(t *mojom.UserDefinedConstant) *mojom_types.Use rDefinedValueDeclaredConstant { 426 func translateUserDefinedConstant(t *mojom.UserDefinedConstant) *mojom_types.Use rDefinedValueDeclaredConstant {
427 declaredConstant := mojom_types.UserDefinedValueDeclaredConstant{} 427 declaredConstant := mojom_types.UserDefinedValueDeclaredConstant{}
428 declaredConstant.Value.Type = translateTypeRef(t.DeclaredType()) 428 declaredConstant.Value.Type = translateTypeRef(t.DeclaredType())
429 declaredConstant.Value.DeclData = *translateDeclarationData(&t.Declarati onData) 429 declaredConstant.Value.DeclData = *translateDeclarationData(&t.Declarati onData)
430 declaredConstant.Value.Value = translateValueRef(t.ValueRef()) 430 declaredConstant.Value.Value = translateValueRef(t.ValueRef())
431 » // TODO(rudominer) implement UserDefinedValue.resolved_concrete_value. 431 » // We set the |resolved_concrete_value| field only in the following situ ation.
432 » // declaredConstant.ResolvedConcreteValue = 432 » // See the comments in mojom_types.mojom.
433 » // translateConcreteValue(t.ValueRef().ResolvedConcreteValue())) 433 » if _, ok := declaredConstant.Value.Value.(*mojom_types.ValueUserValueRef erence); ok {
434 » » // If the type of the |value| field is a UserValueReference...
435 » » userValueRef := t.ValueRef().(*mojom.UserValueRef)
436 » » if _, ok := userValueRef.ResolvedDeclaredValue().(*mojom.UserDef inedConstant); ok {
437 » » » // and if that reference resolves to a user-defined cons tant.
438 » » » declaredConstant.Value.ResolvedConcreteValue = translate ConcreteValue(t.ValueRef().ResolvedConcreteValue())
439 » » }
440 » }
441
434 return &declaredConstant 442 return &declaredConstant
435 } 443 }
436 444
437 func translateEnumValue(v *mojom.EnumValue) mojom_types.EnumValue { 445 func translateEnumValue(v *mojom.EnumValue) mojom_types.EnumValue {
438 enumValue := mojom_types.EnumValue{} 446 enumValue := mojom_types.EnumValue{}
439 enumValue.DeclData = translateDeclarationData(&v.DeclarationData) 447 enumValue.DeclData = translateDeclarationData(&v.DeclarationData)
440 enumValue.EnumTypeKey = v.EnumType().TypeKey() 448 enumValue.EnumTypeKey = v.EnumType().TypeKey()
441 if v.ValueRef() != nil { 449 if v.ValueRef() != nil {
442 enumValue.InitializerValue = translateValueRef(v.ValueRef()) 450 enumValue.InitializerValue = translateValueRef(v.ValueRef())
443 } 451 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 switch valueRef := valueRef.(type) { 557 switch valueRef := valueRef.(type) {
550 case mojom.LiteralValue: 558 case mojom.LiteralValue:
551 return translateLiteralValue(valueRef) 559 return translateLiteralValue(valueRef)
552 case *mojom.UserValueRef: 560 case *mojom.UserValueRef:
553 return translateUserValueRef(valueRef) 561 return translateUserValueRef(valueRef)
554 default: 562 default:
555 panic(fmt.Sprintf("Unexpected ValueRef type %T", valueRef)) 563 panic(fmt.Sprintf("Unexpected ValueRef type %T", valueRef))
556 } 564 }
557 } 565 }
558 566
567 func translateConcreteValue(cv mojom.ConcreteValue) mojom_types.Value {
568 switch cv := cv.(type) {
569 case mojom.LiteralValue:
570 return translateLiteralValue(cv)
571 // NOTE: See the comments at the top of types.go for a discussion of the difference
572 // between a value and a value reference. In this function we are transl ating a
573 // value, not a value reference. In the case of a LiteralValue or a
574 // BuiltInConstantValue the distinction is immaterial. But in the case o f an
575 // enum value the distinction is important. Here we are building and ret urning
576 // a synthetic mojom_types.UserValueReference to represent the enum valu e.
577 // It is only the |value_key| field that needs to be populated. It does not
578 // make sense to populate the |identifier| field for example because we
579 // aren't representing any actual occrence in the .mojom file.
580 case *mojom.EnumValue:
581 return &mojom_types.ValueUserValueReference{mojom_types.UserValu eReference{
582 ValueKey: stringPointer(cv.ValueKey())}}
583 case mojom.BuiltInConstantValue:
584 return translateBuiltInConstantValue(cv)
585 default:
586 panic(fmt.Sprintf("Unexpected ConcreteValue type %T", cv))
587 }
588 }
589
559 func translateLiteralValue(v mojom.LiteralValue) *mojom_types.ValueLiteralValue { 590 func translateLiteralValue(v mojom.LiteralValue) *mojom_types.ValueLiteralValue {
560 var lv mojom_types.LiteralValue 591 var lv mojom_types.LiteralValue
561 switch v.ValueType() { 592 switch v.ValueType() {
562 case mojom.SimpleTypeBool: 593 case mojom.SimpleTypeBool:
563 lv = &mojom_types.LiteralValueBoolValue{v.Value().(bool)} 594 lv = &mojom_types.LiteralValueBoolValue{v.Value().(bool)}
564 case mojom.SimpleTypeDouble: 595 case mojom.SimpleTypeDouble:
565 lv = &mojom_types.LiteralValueDoubleValue{v.Value().(float64)} 596 lv = &mojom_types.LiteralValueDoubleValue{v.Value().(float64)}
566 case mojom.SimpleTypeFloat: 597 case mojom.SimpleTypeFloat:
567 lv = &mojom_types.LiteralValueFloatValue{v.Value().(float32)} 598 lv = &mojom_types.LiteralValueFloatValue{v.Value().(float32)}
568 case mojom.SimpleTypeInt8: 599 case mojom.SimpleTypeInt8:
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 753
723 // stringPointer is a convenience function for creating a pointer to a string wh ose value 754 // stringPointer is a convenience function for creating a pointer to a string wh ose value
724 // is the specified string. It may be used in situations where the compiler will 755 // is the specified string. It may be used in situations where the compiler will
725 // not allow you to take the address of a string value directly, such as the 756 // not allow you to take the address of a string value directly, such as the
726 // return value of a function. It is necessary to create pointers to strings bec ause 757 // return value of a function. It is necessary to create pointers to strings bec ause
727 // that is how the Mojom type |string?| (i.e. nullable string) is represented in 758 // that is how the Mojom type |string?| (i.e. nullable string) is represented in
728 // in the Mojom Go bindings. 759 // in the Mojom Go bindings.
729 func stringPointer(s string) *string { 760 func stringPointer(s string) *string {
730 return &s 761 return &s
731 } 762 }
OLDNEW
« no previous file with comments | « mojom/mojom_tool/mojom/user_defined_types_test.go ('k') | mojom/mojom_tool/serialization/serialization_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698