| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // This program reads from standard input a serialized MojomFileGraph | 5 // This program reads from standard input a serialized MojomFileGraph |
| 6 // (See mojo/public/interfaces/bindings/mojom_files.mojom) as output by the | 6 // (See mojo/public/interfaces/bindings/mojom_files.mojom) as output by the |
| 7 // mojom parser and outputs a list of types and constants defined in the files | 7 // mojom parser and outputs a list of types and constants defined in the files |
| 8 // in the file graph. The output for each file is located in a directory | 8 // in the file graph. The output for each file is located in a directory |
| 9 // structure based on the file's module namespace and in a file named after the | 9 // structure based on the file's module namespace and in a file named after the |
| 10 // processed file. | 10 // processed file. |
| 11 // For example, for file foo.mojom with module namespace abc.bcd, the output | 11 // For example, for file foo.mojom with module namespace abc.bcd, the output |
| 12 // will be located in abc/bcd/foo.mojom.sample. | 12 // will be located in abc/bcd/foo.mojom.sample. |
| 13 // | 13 // |
| 14 // This program is intended as an example for those who would want | 14 // This program is intended as an example for those who would want |
| 15 // to use the output of the mojom parser such as code generator authors. | 15 // to use the output of the mojom parser such as code generator authors. |
| 16 | 16 |
| 17 package main | 17 package main |
| 18 | 18 |
| 19 import ( | 19 import ( |
| 20 "bufio" | 20 "bufio" |
| 21 "io/ioutil" | 21 "io/ioutil" |
| 22 "log" | 22 "log" |
| 23 "os" | 23 "os" |
| 24 "path" | 24 "path" |
| 25 "strings" | 25 "strings" |
| 26 "text/template" | 26 "text/template" |
| 27 | 27 |
| 28 "mojo/public/go/bindings" | 28 "mojo/public/go/bindings" |
| 29 » "mojom/mojom_tool/generated/mojom_files" | 29 » "mojom/generated/mojom_files" |
| 30 » "mojom/mojom_tool/generated/mojom_types" | 30 » "mojom/generated/mojom_types" |
| 31 ) | 31 ) |
| 32 | 32 |
| 33 func main() { | 33 func main() { |
| 34 inputBytes, err := ioutil.ReadAll(os.Stdin) | 34 inputBytes, err := ioutil.ReadAll(os.Stdin) |
| 35 if err != nil { | 35 if err != nil { |
| 36 log.Fatalf("failed to read: %v", err) | 36 log.Fatalf("failed to read: %v", err) |
| 37 } | 37 } |
| 38 | 38 |
| 39 decoder := bindings.NewDecoder(inputBytes, nil) | 39 decoder := bindings.NewDecoder(inputBytes, nil) |
| 40 fileGraph := mojom_files.MojomFileGraph{} | 40 fileGraph := mojom_files.MojomFileGraph{} |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 constNames := make([]string, len(*constKeys)) | 178 constNames := make([]string, len(*constKeys)) |
| 179 | 179 |
| 180 for index, constKey := range *constKeys { | 180 for index, constKey := range *constKeys { |
| 181 userDefinedValue := fileGraph.ResolvedValues[constKey] | 181 userDefinedValue := fileGraph.ResolvedValues[constKey] |
| 182 declaredConstant := userDefinedValue.Interface().(mojom_types.De
claredConstant) | 182 declaredConstant := userDefinedValue.Interface().(mojom_types.De
claredConstant) |
| 183 constNames[index] = *declaredConstant.DeclData.ShortName | 183 constNames[index] = *declaredConstant.DeclData.ShortName |
| 184 } | 184 } |
| 185 | 185 |
| 186 return constNames | 186 return constNames |
| 187 } | 187 } |
| OLD | NEW |