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

Unified Diff: mojom/generators/go/translator/names.go

Issue 2233963003: Add support for constants in the new go generator. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Merge branch 'master' of github.com:domokit/mojo into const Created 4 years, 4 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
Index: mojom/generators/go/translator/names.go
diff --git a/mojom/generators/go/translator/names.go b/mojom/generators/go/translator/names.go
index 210ee71cf551068b98d1fa718d21e6326885e385..2b26f7f375e47d88e4b784181de37402c18b13b9 100644
--- a/mojom/generators/go/translator/names.go
+++ b/mojom/generators/go/translator/names.go
@@ -36,12 +36,38 @@ func (t *translator) goTypeName(typeKey string) string {
return goType
}
+func (t *translator) goConstName(constKey string) (name string) {
+ if cachedName, ok := t.goConstNameCache[constKey]; ok {
+ return cachedName
+ }
+
+ declaredConstant := t.fileGraph.ResolvedConstants[constKey]
+
+ name = formatName(*declaredConstant.DeclData.ShortName)
+ if declaredConstant.DeclData.ContainerTypeKey != nil {
+ containerName := t.goTypeName(*declaredConstant.DeclData.ContainerTypeKey)
+ name = fmt.Sprintf("%s_%s", containerName, name)
+ }
+
+ return
+}
+
func fileNameToPackageName(fileName string) string {
base := filepath.Base(fileName)
ext := filepath.Ext(base)
return base[:len(base)-len(ext)]
}
+func (t *translator) importMojomFile(fileName string) {
+ pkgName := fileNameToPackageName(fileName)
+ pkgPath, err := filepath.Rel(t.Config.SrcRootPath(), fileName)
+ if err != nil {
+ panic(err.Error())
+ }
+ pkgPath = pkgPath[:len(pkgPath)-len(filepath.Ext(pkgPath))]
+ t.imports[pkgName] = pkgPath
+}
+
func userDefinedTypeDeclData(userDefinedType mojom_types.UserDefinedType) *mojom_types.DeclarationData {
switch u := userDefinedType.(type) {
case *mojom_types.UserDefinedTypeEnumType:

Powered by Google App Engine
This is Rietveld 408576698