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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/mojom_parser/generators/common/common.go
diff --git a/mojom/mojom_parser/generators/common/common.go b/mojom/mojom_parser/generators/common/common.go
new file mode 100644
index 0000000000000000000000000000000000000000..aff5e28eddd94e83585e0039b7240d5f11248930
--- /dev/null
+++ b/mojom/mojom_parser/generators/common/common.go
@@ -0,0 +1,57 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package common
+
+import (
+ "mojom/mojom_parser/generated/mojom_files"
+)
+
+// common groups together functions which make it easier for generators
+// implemented in go to implement the same interface.
+
+// GeneratorConfig is used to specify configuration for a generator.
+type GeneratorConfig interface {
+ // FileGraph returns a parsed MojomFileGraph.
+ FileGraph() *mojom_files.MojomFileGraph
+
+ // OutputDir returns an absolute path in which generator output must be
+ // written.
+ OutputDir() string
+
+ // SrcRootPath returns an absolute path to the root of the source tree. This
+ // is used to compute the relative path from the root of the source tree to
+ // mojom files for which output is to be generated.
+ SrcRootPath() string
+
+ // GenImports returns true if the generator should generate output files for
+ // all of the files in the provided file graph, including those that were not
+ // specified on the command line but are only present because they were
+ // referenced in an import statement. It returns false if the generator should
+ // generate output files only for the files which were explicitly specified
+ // (as indicated by the fact that they have a non-empty |SpecifiedFileName|).
+ GenImports() bool
+}
+
+// Writer is the interface used by the generators to write their output.
+// It is also made to faciliate testing by allowing generator code to write
+// to a provided buffer such as a bytes.Buffer.
+type Writer interface {
+ WriteString(s string) (n int, err error)
+}
+
+// writeOutput is the type of the generator function which writes the specified
+// file's generated code.
+type writeOutput func(fileName string, config GeneratorConfig)
+
+// GenerateOutput iterates through the files in the file graph in |config| and
+// for all the files for which an output should be generated, it uses
+// writeOutput to write the generated output.
+func GenerateOutput(writeOutput writeOutput, config GeneratorConfig) {
+ for fileName, file := range config.FileGraph().Files {
+ if config.GenImports() || *file.SpecifiedFileName != "" {
+ writeOutput(fileName, config)
+ }
+ }
+}
« 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