| 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 package common | 5 package common |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "io" | 8 "io" |
| 9 "mojom/generated/mojom_files" | 9 "mojom/generated/mojom_files" |
| 10 ) | 10 ) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // mojom files for which output is to be generated. | 26 // mojom files for which output is to be generated. |
| 27 SrcRootPath() string | 27 SrcRootPath() string |
| 28 | 28 |
| 29 // GenImports returns true if the generator should generate output files
for | 29 // GenImports returns true if the generator should generate output files
for |
| 30 // all of the files in the provided file graph, including those that wer
e not | 30 // all of the files in the provided file graph, including those that wer
e not |
| 31 // specified on the command line but are only present because they were | 31 // specified on the command line but are only present because they were |
| 32 // referenced in an import statement. It returns false if the generator
should | 32 // referenced in an import statement. It returns false if the generator
should |
| 33 // generate output files only for the files which were explicitly specif
ied | 33 // generate output files only for the files which were explicitly specif
ied |
| 34 // (as indicated by the fact that they have a non-empty |SpecifiedFileNa
me|). | 34 // (as indicated by the fact that they have a non-empty |SpecifiedFileNa
me|). |
| 35 GenImports() bool | 35 GenImports() bool |
| 36 |
| 37 // GenTypeInfo returns true if the generator should generate type inform
ation |
| 38 // describing the mojom file it is generating for. This type information
is a |
| 39 // typically a serialized mojom describing all data types defined in a m
ojom, |
| 40 // which can be used for mojom type-introspection. |
| 41 GenTypeInfo() bool |
| 36 } | 42 } |
| 37 | 43 |
| 38 // Writer is the interface used by the generators to write their output. | 44 // Writer is the interface used by the generators to write their output. |
| 39 // It is also made to faciliate testing by allowing generator code to write | 45 // It is also made to faciliate testing by allowing generator code to write |
| 40 // to a provided buffer such as a bytes.Buffer. | 46 // to a provided buffer such as a bytes.Buffer. |
| 41 type Writer interface { | 47 type Writer interface { |
| 42 io.Writer | 48 io.Writer |
| 43 WriteString(s string) (n int, err error) | 49 WriteString(s string) (n int, err error) |
| 44 } | 50 } |
| 45 | 51 |
| 46 // writeOutput is the type of the generator function which writes the specified | 52 // writeOutput is the type of the generator function which writes the specified |
| 47 // file's generated code. | 53 // file's generated code. |
| 48 type writeOutput func(fileName string, config GeneratorConfig) | 54 type writeOutput func(fileName string, config GeneratorConfig) |
| 49 | 55 |
| 50 // GenerateOutput iterates through the files in the file graph in |config| and | 56 // GenerateOutput iterates through the files in the file graph in |config| and |
| 51 // for all the files for which an output should be generated, it uses | 57 // for all the files for which an output should be generated, it uses |
| 52 // writeOutput to write the generated output. | 58 // writeOutput to write the generated output. |
| 53 func GenerateOutput(writeOutput writeOutput, config GeneratorConfig) { | 59 func GenerateOutput(writeOutput writeOutput, config GeneratorConfig) { |
| 54 for fileName, file := range config.FileGraph().Files { | 60 for fileName, file := range config.FileGraph().Files { |
| 55 if config.GenImports() || *file.SpecifiedFileName != "" { | 61 if config.GenImports() || *file.SpecifiedFileName != "" { |
| 56 writeOutput(fileName, config) | 62 writeOutput(fileName, config) |
| 57 } | 63 } |
| 58 } | 64 } |
| 59 } | 65 } |
| OLD | NEW |