blob: 2ec7c9bf087ddc4a8432cba79b20b62642aab853 [file] [log] [blame]
// Copyright 2015 The Vanadium 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 vdltool defines types used by the vdl tool itself, including the
// format of vdl.config files.
package vdltool
// Config specifies the configuration for the vdl tool. This is typically
// represented in optional "vdl.config" files in each vdl source package. Each
// vdl.config file implicitly imports this package. E.g. you may refer to
// vdltool.Config in the "vdl.config" file without explicitly importing vdltool.
type Config struct {
// GenLanguages restricts the set of code generation languages. If the set is
// empty, all supported languages are allowed to be generated.
GenLanguages set[GenLanguage]
// Language-specific configurations.
Go GoConfig
Java JavaConfig
Javascript JavascriptConfig
}
// GenLanguage enumerates the known code generation languages.
type GenLanguage enum {
Go
Java
Javascript
}
// GoConfig specifies go specific configuration.
type GoConfig struct {
// WireToNativeTypes specifies the mapping from a VDL wire type to its Go
// native type representation. This is rarely used and easy to configure
// incorrectly; usage is currently restricted to packages that are explicitly
// whitelisted.
//
// WireToNativeTypes are meant for scenarios where there is an idiomatic Go
// type used in your code, but you need a standard VDL representation for wire
// compatibility. E.g. the VDL time package defines Duration and Time for
// wire compatibility, but we want the generated code to use the standard Go
// time package.
//
// The key of the map is the name of the VDL type (aka WireType), which must
// be defined in the vdl package associated with the vdl.config file.
//
// The code generator assumes the existence of a pair of conversion functions
// converting between the wire and native types, and will automatically call
// vdl.RegisterNative with these function names.
//
// Assuming the name of the WireType is Foo:
// func fooToNative(x Foo, n *Native) error
// func fooFromNative(x *Foo, n Native) error
WireToNativeTypes map[string]GoType
}
// GoType describes the Go type information associated with a VDL type.
// See v.io/x/ref/lib/vdl/testdata/native for examples.
type GoType struct {
// Type is the Go type to use in generated code, instead of the VDL type. If
// the Go type requires additional imports, specify the type using the
// standard local package name here, and also specify the import package in
// Imports.
Type string
// Imports are the Go imports to use in generated code, required by the Type.
Imports []GoImport
}
// GoImport describes Go import information.
type GoImport struct {
// Path is the package path that uniquely identifies the imported package.
Path string
// Name is the name of the package identified by Path. Due to Go conventions,
// it is typically just the basename of Path, but may be set to something
// different if the imported package doesn't follow Go conventions.
Name string
}
// JavaConfig specifies java specific configuration.
type JavaConfig struct {
// WireToNativeTypes specifies the mapping from a VDL wire type to its Java
// native type representation. This is rarely used and easy to configure
// incorrectly; usage is currently restricted to packages that are explicitly
// whitelisted.
//
// WireToNativeTypes are meant for scenarios where there is an idiomatic Java
// type used in your code, but you need a standard VDL representation for wire
// compatibility. E.g. the VDL time package defines Duration and Time for
// wire compatibility, but we want the generated code to use the org.joda.time
// package.
//
// The key of the map is the name of the VDL type (aka WireType), which must
// be defined in the vdl package associated with the vdl.config file.
//
// The code generator assumes that the conversion functions will be registered
// in java vdl package.
WireToNativeTypes map[string]string
// WireTypeRenames specifies the mapping from a VDL wire type name to its
// Java native type name.
//
// WireTypeRenames are meant for scenarios where the VDL wire name
// conflicts in some way with the Java native names, e.g., a VDL Integer
// type could be named VInteger for clarity.
//
// When combined with WireToNativeTypes, this feature allows us to attach
// functions to VDL types. For example, we may rename AccessList VDL type
// into WireAccessList and then map WireAccessList to our Java native type
// AccessList which defines functions on the VDL data.
//
// The key of the map is the name of the VDL wire type, which must be
// defined in the vdl package associated with the vdl.config file.
WireTypeRenames map[string]string
}
// JavascriptConfig specifies javascript specific configuration.
type JavascriptConfig struct {
}