Index: mojom/generators/go/translator/translator.go |
diff --git a/mojom/generators/go/translator/translator.go b/mojom/generators/go/translator/translator.go |
index 5679e384d982626bbf56935c0cdb4db7c02627b6..711a017989e7cac43bcc5bf2cda5a2216c3a8b82 100644 |
--- a/mojom/generators/go/translator/translator.go |
+++ b/mojom/generators/go/translator/translator.go |
@@ -21,17 +21,19 @@ type Translator interface { |
type translator struct { |
fileGraph *mojom_files.MojomFileGraph |
// goTypeCache maps type keys to go type strings. |
- goTypeCache map[string]string |
- imports map[string]string |
- currentFileName string |
- pkgName string |
- Config common.GeneratorConfig |
+ goTypeCache map[string]string |
+ goConstNameCache map[string]string |
+ imports map[string]string |
+ currentFileName string |
+ pkgName string |
+ Config common.GeneratorConfig |
} |
func NewTranslator(fileGraph *mojom_files.MojomFileGraph) (t *translator) { |
t = new(translator) |
t.fileGraph = fileGraph |
t.goTypeCache = map[string]string{} |
+ t.goConstNameCache = map[string]string{} |
t.imports = map[string]string{} |
return t |
} |
@@ -94,6 +96,25 @@ func (t *translator) TranslateMojomFile(fileName string) (tmplFile *TmplFile) { |
} |
} |
+ if file.DeclaredMojomObjects.TopLevelConstants == nil { |
+ file.DeclaredMojomObjects.TopLevelConstants = &[]string{} |
+ } |
+ if file.DeclaredMojomObjects.EmbeddedConstants == nil { |
+ file.DeclaredMojomObjects.EmbeddedConstants = &[]string{} |
+ } |
+ for _, constKey := range *file.DeclaredMojomObjects.TopLevelConstants { |
+ c := t.translateDeclaredConstant(constKey) |
+ if c != nil { |
+ tmplFile.Constants = append(tmplFile.Constants, c) |
+ } |
+ } |
+ for _, constKey := range *file.DeclaredMojomObjects.EmbeddedConstants { |
+ c := t.translateDeclaredConstant(constKey) |
+ if c != nil { |
+ tmplFile.Constants = append(tmplFile.Constants, c) |
+ } |
+ } |
+ |
tmplFile.Imports = []Import{} |
tmplFile.MojomImports = []string{} |
@@ -299,6 +320,20 @@ func (t *translator) translateMojomMethod(mojomMethod mojom_types.MojomMethod, i |
return m |
} |
+func (t *translator) translateDeclaredConstant(constKey string) (c *ConstantTemplate) { |
+ declaredConstant := t.fileGraph.ResolvedConstants[constKey] |
+ resolvedValue := t.resolveConstRef(declaredConstant.Value) |
+ if _, ok := resolvedValue.(*mojom_types.ValueBuiltinValue); ok { |
+ // There is no way to have a constant NaN, or infinity in go. |
+ return nil |
+ } |
+ c = new(ConstantTemplate) |
+ c.Name = t.goConstName(constKey) |
+ c.Type = t.translateType(declaredConstant.Type) |
+ c.Value = t.translateValue(declaredConstant.Value) |
+ return c |
+} |
+ |
//////////////////////////////////////////////////////////////////////////////// |
// Implements sort.Interface. |