vdltool

package
v0.0.0-...-e3ab1ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2016 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package vdltool defines types used by the vdl tool itself, including the format of vdl.config files.

Index

Constants

This section is empty.

Variables

GenLanguageAll holds all labels for GenLanguage.

GoKindAll holds all labels for GoKind.

GoZeroModeAll holds all labels for GoZeroMode.

Functions

This section is empty.

Types

type Config

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 map[GenLanguage]struct{}
	// Language-specific configurations.
	Go         GoConfig
	Java       JavaConfig
	Javascript JavascriptConfig
	Swift      SwiftConfig
}

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.

func (*Config) FillVDLTarget

func (m *Config) FillVDLTarget(t vdl.Target, tt *vdl.Type) error

func (*Config) MakeVDLTarget

func (m *Config) MakeVDLTarget() vdl.Target

func (Config) VDLIsZero

func (x Config) VDLIsZero() bool

func (*Config) VDLRead

func (x *Config) VDLRead(dec vdl.Decoder) error

func (Config) VDLWrite

func (x Config) VDLWrite(enc vdl.Encoder) error

type ConfigTarget

type ConfigTarget struct {
	Value *Config

	vdl.TargetBase
	vdl.FieldsTargetBase
}

func (*ConfigTarget) FinishField

func (t *ConfigTarget) FinishField(_, _ vdl.Target) error

func (*ConfigTarget) FinishFields

func (t *ConfigTarget) FinishFields(_ vdl.FieldsTarget) error

func (*ConfigTarget) StartField

func (t *ConfigTarget) StartField(name string) (key, field vdl.Target, _ error)

func (*ConfigTarget) StartFields

func (t *ConfigTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error)

func (*ConfigTarget) ZeroField

func (t *ConfigTarget) ZeroField(name string) error

type GenLanguage

type GenLanguage int

GenLanguage enumerates the known code generation languages.

const (
	GenLanguageGo GenLanguage = iota
	GenLanguageJava
	GenLanguageJavascript
	GenLanguageSwift
)

func GenLanguageFromString

func GenLanguageFromString(label string) (x GenLanguage, err error)

GenLanguageFromString creates a GenLanguage from a string label.

func (*GenLanguage) FillVDLTarget

func (m *GenLanguage) FillVDLTarget(t vdl.Target, tt *vdl.Type) error

func (*GenLanguage) MakeVDLTarget

func (m *GenLanguage) MakeVDLTarget() vdl.Target

func (*GenLanguage) Set

func (x *GenLanguage) Set(label string) error

Set assigns label to x.

func (GenLanguage) String

func (x GenLanguage) String() string

String returns the string label of x.

func (GenLanguage) VDLIsZero

func (x GenLanguage) VDLIsZero() bool

func (*GenLanguage) VDLRead

func (x *GenLanguage) VDLRead(dec vdl.Decoder) error

func (GenLanguage) VDLWrite

func (x GenLanguage) VDLWrite(enc vdl.Encoder) error

type GenLanguageTarget

type GenLanguageTarget struct {
	Value *GenLanguage
	vdl.TargetBase
}

func (*GenLanguageTarget) FromEnumLabel

func (t *GenLanguageTarget) FromEnumLabel(src string, tt *vdl.Type) error

type GoConfig

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
}

GoConfig specifies go specific configuration.

func (*GoConfig) FillVDLTarget

func (m *GoConfig) FillVDLTarget(t vdl.Target, tt *vdl.Type) error

func (*GoConfig) MakeVDLTarget

func (m *GoConfig) MakeVDLTarget() vdl.Target

func (GoConfig) VDLIsZero

func (x GoConfig) VDLIsZero() bool

func (*GoConfig) VDLRead

func (x *GoConfig) VDLRead(dec vdl.Decoder) error

func (GoConfig) VDLWrite

func (x GoConfig) VDLWrite(enc vdl.Encoder) error

type GoConfigTarget

type GoConfigTarget struct {
	Value *GoConfig

	vdl.TargetBase
	vdl.FieldsTargetBase
}

func (*GoConfigTarget) FinishField

func (t *GoConfigTarget) FinishField(_, _ vdl.Target) error

func (*GoConfigTarget) FinishFields

func (t *GoConfigTarget) FinishFields(_ vdl.FieldsTarget) error

func (*GoConfigTarget) StartField

func (t *GoConfigTarget) StartField(name string) (key, field vdl.Target, _ error)

func (*GoConfigTarget) StartFields

func (t *GoConfigTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error)

func (*GoConfigTarget) ZeroField

func (t *GoConfigTarget) ZeroField(name string) error

type GoImport

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
}

GoImport describes Go import information.

func (*GoImport) FillVDLTarget

func (m *GoImport) FillVDLTarget(t vdl.Target, tt *vdl.Type) error

func (*GoImport) MakeVDLTarget

func (m *GoImport) MakeVDLTarget() vdl.Target

func (GoImport) VDLIsZero

func (x GoImport) VDLIsZero() bool

func (*GoImport) VDLRead

func (x *GoImport) VDLRead(dec vdl.Decoder) error

func (GoImport) VDLWrite

func (x GoImport) VDLWrite(enc vdl.Encoder) error

type GoImportTarget

type GoImportTarget struct {
	Value *GoImport

	vdl.TargetBase
	vdl.FieldsTargetBase
}

func (*GoImportTarget) FinishField

func (t *GoImportTarget) FinishField(_, _ vdl.Target) error

func (*GoImportTarget) FinishFields

func (t *GoImportTarget) FinishFields(_ vdl.FieldsTarget) error

func (*GoImportTarget) StartField

func (t *GoImportTarget) StartField(name string) (key, field vdl.Target, _ error)

func (*GoImportTarget) StartFields

func (t *GoImportTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error)

func (*GoImportTarget) ZeroField

func (t *GoImportTarget) ZeroField(name string) error

type GoKind

type GoKind int

GoKind describes the kind of Go type.

const (
	GoKindStruct GoKind = iota
	GoKindBool
	GoKindNumber
	GoKindString
	GoKindArray
	GoKindSlice
	GoKindMap
	GoKindPointer
)

func GoKindFromString

func GoKindFromString(label string) (x GoKind, err error)

GoKindFromString creates a GoKind from a string label.

func (*GoKind) FillVDLTarget

func (m *GoKind) FillVDLTarget(t vdl.Target, tt *vdl.Type) error

func (*GoKind) MakeVDLTarget

func (m *GoKind) MakeVDLTarget() vdl.Target

func (*GoKind) Set

func (x *GoKind) Set(label string) error

Set assigns label to x.

func (GoKind) String

func (x GoKind) String() string

String returns the string label of x.

func (GoKind) VDLIsZero

func (x GoKind) VDLIsZero() bool

func (*GoKind) VDLRead

func (x *GoKind) VDLRead(dec vdl.Decoder) error

func (GoKind) VDLWrite

func (x GoKind) VDLWrite(enc vdl.Encoder) error

type GoKindTarget

type GoKindTarget struct {
	Value *GoKind
	vdl.TargetBase
}

func (*GoKindTarget) FromEnumLabel

func (t *GoKindTarget) FromEnumLabel(src string, tt *vdl.Type) error

type GoType

type GoType struct {
	// Kind is the kind of Type.
	Kind GoKind
	// 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.  E.g. to specify the native type time.Duration:
	//   Kind:    Number
	//   Type:    "time.Duration",
	//   Imports: {{Path: "time", Name: "time"}},
	//   Zero:    {Mode: Unique}
	Type string
	// Imports are the Go imports required by the Type, used in generated code.
	Imports []GoImport
	// Zero specifies special behavior for zero value setting and checking.
	Zero GoZero
}

GoType describes the Go type information associated with a VDL type. See v.io/x/ref/lib/vdl/testdata/native for examples.

func (*GoType) FillVDLTarget

func (m *GoType) FillVDLTarget(t vdl.Target, tt *vdl.Type) error

func (*GoType) MakeVDLTarget

func (m *GoType) MakeVDLTarget() vdl.Target

func (GoType) VDLIsZero

func (x GoType) VDLIsZero() bool

func (*GoType) VDLRead

func (x *GoType) VDLRead(dec vdl.Decoder) error

func (GoType) VDLWrite

func (x GoType) VDLWrite(enc vdl.Encoder) error

type GoTypeTarget

type GoTypeTarget struct {
	Value *GoType

	vdl.TargetBase
	vdl.FieldsTargetBase
}

func (*GoTypeTarget) FinishField

func (t *GoTypeTarget) FinishField(_, _ vdl.Target) error

func (*GoTypeTarget) FinishFields

func (t *GoTypeTarget) FinishFields(_ vdl.FieldsTarget) error

func (*GoTypeTarget) StartField

func (t *GoTypeTarget) StartField(name string) (key, field vdl.Target, _ error)

func (*GoTypeTarget) StartFields

func (t *GoTypeTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error)

func (*GoTypeTarget) ZeroField

func (t *GoTypeTarget) ZeroField(name string) error

type GoZero

type GoZero struct {
	Mode GoZeroMode
	// IsZero specifies a field, method or function that returns true iff the
	// native value represents the VDL zero value.
	//
	// If IsZero starts with a dot (.), it is assumed to be a field or method.
	// The field type or method return type must be bool.  Generated code will
	// apply the IsZero string verbatim to expressions of the native type.
	//
	// If IsZero doesn't start with a dot(.), it is assumed to be a function whose
	// return type must be bool.  Generated code will call the function with all
	// occurrences of XXX replaced with an expression of the native type.
	//
	// TODO(toddw): The function form of IsZero isn't implemented, and also needs
	// another field to handle imports:
	//    IsZeroImports []GoImport
	IsZero string
}

GoZero describes Go zero value behavior.

REQUIRED: Either Mode == Unique or IsZero is set. We will not perform native/wire conversions to check zero values.

func (*GoZero) FillVDLTarget

func (m *GoZero) FillVDLTarget(t vdl.Target, tt *vdl.Type) error

func (*GoZero) MakeVDLTarget

func (m *GoZero) MakeVDLTarget() vdl.Target

func (GoZero) VDLIsZero

func (x GoZero) VDLIsZero() bool

func (*GoZero) VDLRead

func (x *GoZero) VDLRead(dec vdl.Decoder) error

func (GoZero) VDLWrite

func (x GoZero) VDLWrite(enc vdl.Encoder) error

type GoZeroMode

type GoZeroMode int

GoZeroMode describes the relationship between the Go zero value of the native type, and the VDL zero value.

const (
	GoZeroModeUnknown GoZeroMode = iota
	GoZeroModeCanonical
	GoZeroModeUnique
)

func GoZeroModeFromString

func GoZeroModeFromString(label string) (x GoZeroMode, err error)

GoZeroModeFromString creates a GoZeroMode from a string label.

func (*GoZeroMode) FillVDLTarget

func (m *GoZeroMode) FillVDLTarget(t vdl.Target, tt *vdl.Type) error

func (*GoZeroMode) MakeVDLTarget

func (m *GoZeroMode) MakeVDLTarget() vdl.Target

func (*GoZeroMode) Set

func (x *GoZeroMode) Set(label string) error

Set assigns label to x.

func (GoZeroMode) String

func (x GoZeroMode) String() string

String returns the string label of x.

func (GoZeroMode) VDLIsZero

func (x GoZeroMode) VDLIsZero() bool

func (*GoZeroMode) VDLRead

func (x *GoZeroMode) VDLRead(dec vdl.Decoder) error

func (GoZeroMode) VDLWrite

func (x GoZeroMode) VDLWrite(enc vdl.Encoder) error

type GoZeroModeTarget

type GoZeroModeTarget struct {
	Value *GoZeroMode
	vdl.TargetBase
}

func (*GoZeroModeTarget) FromEnumLabel

func (t *GoZeroModeTarget) FromEnumLabel(src string, tt *vdl.Type) error

type GoZeroTarget

type GoZeroTarget struct {
	Value *GoZero

	vdl.TargetBase
	vdl.FieldsTargetBase
}

func (*GoZeroTarget) FinishField

func (t *GoZeroTarget) FinishField(_, _ vdl.Target) error

func (*GoZeroTarget) FinishFields

func (t *GoZeroTarget) FinishFields(_ vdl.FieldsTarget) error

func (*GoZeroTarget) StartField

func (t *GoZeroTarget) StartField(name string) (key, field vdl.Target, _ error)

func (*GoZeroTarget) StartFields

func (t *GoZeroTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error)

func (*GoZeroTarget) ZeroField

func (t *GoZeroTarget) ZeroField(name string) error

type JavaConfig

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
}

JavaConfig specifies java specific configuration.

func (*JavaConfig) FillVDLTarget

func (m *JavaConfig) FillVDLTarget(t vdl.Target, tt *vdl.Type) error

func (*JavaConfig) MakeVDLTarget

func (m *JavaConfig) MakeVDLTarget() vdl.Target

func (JavaConfig) VDLIsZero

func (x JavaConfig) VDLIsZero() bool

func (*JavaConfig) VDLRead

func (x *JavaConfig) VDLRead(dec vdl.Decoder) error

func (JavaConfig) VDLWrite

func (x JavaConfig) VDLWrite(enc vdl.Encoder) error

type JavaConfigTarget

type JavaConfigTarget struct {
	Value *JavaConfig

	vdl.TargetBase
	vdl.FieldsTargetBase
}

func (*JavaConfigTarget) FinishField

func (t *JavaConfigTarget) FinishField(_, _ vdl.Target) error

func (*JavaConfigTarget) FinishFields

func (t *JavaConfigTarget) FinishFields(_ vdl.FieldsTarget) error

func (*JavaConfigTarget) StartField

func (t *JavaConfigTarget) StartField(name string) (key, field vdl.Target, _ error)

func (*JavaConfigTarget) StartFields

func (t *JavaConfigTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error)

func (*JavaConfigTarget) ZeroField

func (t *JavaConfigTarget) ZeroField(name string) error

type JavascriptConfig

type JavascriptConfig struct {
}

JavascriptConfig specifies javascript specific configuration.

func (*JavascriptConfig) FillVDLTarget

func (m *JavascriptConfig) FillVDLTarget(t vdl.Target, tt *vdl.Type) error

func (*JavascriptConfig) MakeVDLTarget

func (m *JavascriptConfig) MakeVDLTarget() vdl.Target

func (JavascriptConfig) VDLIsZero

func (x JavascriptConfig) VDLIsZero() bool

func (*JavascriptConfig) VDLRead

func (x *JavascriptConfig) VDLRead(dec vdl.Decoder) error

func (JavascriptConfig) VDLWrite

func (x JavascriptConfig) VDLWrite(enc vdl.Encoder) error

type JavascriptConfigTarget

type JavascriptConfigTarget struct {
	Value *JavascriptConfig
	vdl.TargetBase
	vdl.FieldsTargetBase
}

func (*JavascriptConfigTarget) FinishField

func (t *JavascriptConfigTarget) FinishField(_, _ vdl.Target) error

func (*JavascriptConfigTarget) FinishFields

func (t *JavascriptConfigTarget) FinishFields(_ vdl.FieldsTarget) error

func (*JavascriptConfigTarget) StartField

func (t *JavascriptConfigTarget) StartField(name string) (key, field vdl.Target, _ error)

func (*JavascriptConfigTarget) StartFields

func (t *JavascriptConfigTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error)

func (*JavascriptConfigTarget) ZeroField

func (t *JavascriptConfigTarget) ZeroField(name string) error

type SwiftConfig

type SwiftConfig struct {
	// WireToNativeTypes specifies the mapping from a VDL wire type to its Swift
	// 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 Swift
	// 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 NSDate or NSTimeInterval
	//
	// 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 Swift vdl package.
	WireToNativeTypes map[string]string
}

SwiftConfig specifies swift specific configuration for this package. Note that despite the SwiftConfig options for a given package (which should be very rare in practice), we still need to know the name of the swift module that this package relates to to properly understand import boundaries between projects/frameworks/modules.

We do this by defining a file called "swiftmodule" that contains JUST the name of the Swift module at the root of your VDL packages. For example, if you have the VDL files for your Xcode project/target called UberForCats at /Users/aaron/uberforcats/vdl, then create /Users/aaron/uberforcats/vdl/com.uberforcats/swiftmodule and have it just contain "UberForCats". We then will treat any VDL files contained in that directory and any subdirectories as part of the UberForCats Swift module, ultimately letting the compiler and will automatically do the right thing if others import your package. If you don't do this then nobody will be able to import your VDL types in Swift, and you might end up with extra long class/pkg names (ComuberforcatsServicesProfit instead of ServicesProfit for $VDLROOT/com.uberforcats/services/profit).

If you are creating multiple Swift modules for a given $VDLROOT then just place swiftmodule files at the logical boundaries. For eample, we do this for v.io/v23 to be exported to the VanadiumCore framework, but everything under v.io/v23/services lives in the VanadiumServices framework.

func (*SwiftConfig) FillVDLTarget

func (m *SwiftConfig) FillVDLTarget(t vdl.Target, tt *vdl.Type) error

func (*SwiftConfig) MakeVDLTarget

func (m *SwiftConfig) MakeVDLTarget() vdl.Target

func (SwiftConfig) VDLIsZero

func (x SwiftConfig) VDLIsZero() bool

func (*SwiftConfig) VDLRead

func (x *SwiftConfig) VDLRead(dec vdl.Decoder) error

func (SwiftConfig) VDLWrite

func (x SwiftConfig) VDLWrite(enc vdl.Encoder) error

type SwiftConfigTarget

type SwiftConfigTarget struct {
	Value *SwiftConfig

	vdl.TargetBase
	vdl.FieldsTargetBase
}

func (*SwiftConfigTarget) FinishField

func (t *SwiftConfigTarget) FinishField(_, _ vdl.Target) error

func (*SwiftConfigTarget) FinishFields

func (t *SwiftConfigTarget) FinishFields(_ vdl.FieldsTarget) error

func (*SwiftConfigTarget) StartField

func (t *SwiftConfigTarget) StartField(name string) (key, field vdl.Target, _ error)

func (*SwiftConfigTarget) StartFields

func (t *SwiftConfigTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error)

func (*SwiftConfigTarget) ZeroField

func (t *SwiftConfigTarget) ZeroField(name string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL