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

Side by Side Diff: mojom/mojom_parser/generators/common/common.go

Issue 1737143003: A mojom .d generator. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Update sha1. Created 4 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package common
6
7 import (
8 "mojom/mojom_parser/generated/mojom_files"
9 )
10
11 // common groups together functions which make it easier for generators
12 // implemented in go to implement the same interface.
13
14 // GeneratorConfig is used to specify configuration for a generator.
15 type GeneratorConfig interface {
16 // FileGraph returns a parsed MojomFileGraph.
17 FileGraph() *mojom_files.MojomFileGraph
18
19 // OutputDir returns an absolute path in which generator output must be
20 // written.
21 OutputDir() string
22
23 // SrcRootPath returns an absolute path to the root of the source tree. This
24 // is used to compute the relative path from the root of the source tree to
25 // mojom files for which output is to be generated.
26 SrcRootPath() string
27
28 // GenImports returns true if the generator should generate output files for
29 // all of the files in the provided file graph, including those that wer e not
30 // specified on the command line but are only present because they were
31 // referenced in an import statement. It returns false if the generator should
32 // generate output files only for the files which were explicitly specif ied
33 // (as indicated by the fact that they have a non-empty |SpecifiedFileNa me|).
34 GenImports() bool
35 }
36
37 // Writer is the interface used by the generators to write their output.
38 // It is also made to faciliate testing by allowing generator code to write
39 // to a provided buffer such as a bytes.Buffer.
40 type Writer interface {
41 WriteString(s string) (n int, err error)
42 }
43
44 // writeOutput is the type of the generator function which writes the specified
45 // file's generated code.
46 type writeOutput func(fileName string, config GeneratorConfig)
47
48 // GenerateOutput iterates through the files in the file graph in |config| and
49 // for all the files for which an output should be generated, it uses
50 // writeOutput to write the generated output.
51 func GenerateOutput(writeOutput writeOutput, config GeneratorConfig) {
52 for fileName, file := range config.FileGraph().Files {
53 if config.GenImports() || *file.SpecifiedFileName != "" {
54 writeOutput(fileName, config)
55 }
56 }
57 }
OLDNEW
« no previous file with comments | « mojom/mojom_parser/generators/common/cli.go ('k') | mojom/mojom_parser/generators/common/util.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698