Documentation ¶
Overview ¶
Package compile implements the VDL compiler, converting a parse tree into compiled results. The CompilePackage function is the main entry point.
Index ¶
- Variables
- func CompileConfig(t *vdl.Type, pconfig *parse.Config, env *Env) *vdl.Value
- func CompileExpr(t *vdl.Type, expr parse.ConstExpr, env *Env) *vdl.Value
- type ConstDef
- type Env
- func (e *Env) DisallowI18nErrorSupport() *Env
- func (e *Env) DisallowPathQualifiers() *Env
- func (e *Env) ErrorI18nSupport() bool
- func (e *Env) Errorf(file *File, pos parse.Pos, format string, v ...interface{})
- func (e *Env) EvalConst(name string, file *File) (opconst.Const, error)
- func (e *Env) FindConstDef(v *vdl.Value) *ConstDef
- func (e *Env) FindTypeDef(t *vdl.Type) *TypeDef
- func (e *Env) ResolveConst(name string, file *File) (cd *ConstDef, matched string)
- func (e *Env) ResolveInterface(name string, file *File) (i *Interface, matched string)
- func (e *Env) ResolvePackage(path string) *Package
- func (e *Env) ResolvePackageGenPath(genPath string) *Package
- func (e *Env) ResolveType(name string, file *File) (td *TypeDef, matched string)
- func (e *Env) Warningf(file *File, pos parse.Pos, format string, v ...interface{})
- type ErrorDef
- type Field
- type File
- type Interface
- type LangFmt
- type Method
- type NamePos
- type Package
- func (p *Package) ConstDefs() (x []*ConstDef)
- func (p *Package) Doc() string
- func (p *Package) ErrorDefs() (x []*ErrorDef)
- func (p *Package) Interfaces() (x []*Interface)
- func (p *Package) QualifiedName(id string) string
- func (p *Package) ResolveConst(name string) *ConstDef
- func (p *Package) ResolveInterface(name string) *Interface
- func (p *Package) ResolveType(name string) *TypeDef
- func (p *Package) String() string
- func (p *Package) TypeDefs() []*TypeDef
- type TypeDef
Constants ¶
This section is empty.
Variables ¶
var ( // BuiltInPackage and BuiltInFile are used to hold the built-ins. BuiltInPackage = newPackage("", "_builtin", "_builtin", vdltool.Config{}) BuiltInFile = &File{BaseName: "_builtin.vdl"} )
Functions ¶
func CompileConfig ¶
CompileConfig compiles a parse.Config into a value. Returns the compiled value on success, or returns nil and guarantees !env.Errors.IsEmpty(). All imports that the parsed config depend on must already have been compiled and populated into env. If t is non-nil, the returned value will be of that type.
func CompileExpr ¶
CompileExpr compiles expr into a value. Returns the compiled value on success, or returns nil and guarantees !env.Errors.IsEmpty(). All imports that expr depends on must already have been compiled and populated into env. If t is non-nil, the returned value will be of that type.
Types ¶
type ConstDef ¶
type ConstDef struct { NamePos // name, parse position and docs Exported bool // is this const definition exported? Value *vdl.Value // const value File *File // parent file that this const is defined in }
ConstDef represents a user-defined named const definition in the compiled results.
type Env ¶
type Env struct { Errors *vdlutil.Errors Warnings *vdlutil.Errors // contains filtered or unexported fields }
Env is the environment for compilation. It contains all errors that were collected during the execution - you can pass Errors to the parse phase to collect all errors together. As packages are compiled it also collects the output; after a sequence of dependent packages is compiled, all compiled output will be collected.
Always create a new Env via NewEnv; the zero Env is invalid.
func NewEnvWithErrors ¶
NewEnvWithErrors creates a new Env, using the given errs to collect errors.
func (*Env) DisallowI18nErrorSupport ¶ added in v0.1.10
DisallowI18nErrorSupport disables i18n formats for errors.
func (*Env) DisallowPathQualifiers ¶
DisallowPathQualifiers disables syntax like "a/b/c".Type.
func (*Env) ErrorI18nSupport ¶ added in v0.1.10
ErrorI18nSupport returns true if i18n support is enabled for errors.
func (*Env) Errorf ¶
Errorf is a helper for error reporting, to consistently contain the file and position of the error when possible.
func (*Env) FindConstDef ¶
FindConstDef returns the const definition corresponding to v, or nil if v isn't a defined const. All user-defined named consts are considered defined; e.g. method tags don't have a corresponding const def.
func (*Env) FindTypeDef ¶
FindTypeDef returns the type definition corresponding to t, or nil if t isn't a defined type. All built-in and user-defined named types are considered defined; e.g. unnamed lists don't have a corresponding type def.
func (*Env) ResolveConst ¶
ResolveConst resolves a name to a const definition. Returns the const def and the portion of name that was matched.
func (*Env) ResolveInterface ¶
ResolveInterface resolves a name to an interface definition. Returns the interface and the portion of name that was matched.
func (*Env) ResolvePackage ¶
ResolvePackage resolves a package path to its previous compiled results.
func (*Env) ResolvePackageGenPath ¶
ResolvePackageGenPath resolves a package gen path to its previous compiled results.
func (*Env) ResolveType ¶
ResolveType resolves a name to a type definition. Returns the type def and the portion of name that was matched.
type ErrorDef ¶
type ErrorDef struct { NamePos // name, parse position and docs Exported bool // is this error definition exported? ID string // error ID RetryCode vdl.WireRetryCode // retry action to be performed by client Params []*Field // list of positional parameter names and types Formats []LangFmt // list of language / format pairs English string // English format text from Formats File *File // parent file that this error is defined in }
ErrorDef represents a user-defined error definition in the compiled results.
type File ¶
type File struct { BaseName string // Base name of the vdl file, e.g. "foo.vdl" PackageDef NamePos // Name, position and docs of the "package" clause TypeDefs []*TypeDef // Types defined in this file ConstDefs []*ConstDef // Consts defined in this file ErrorDefs []*ErrorDef // Errors defined in this file Interfaces []*Interface // Interfaces defined in this file Package *Package // Parent package TypeDeps map[*vdl.Type]bool // Types the file depends on PackageDeps []*Package // Packages the file depends on, sorted by path // contains filtered or unexported fields }
File represents a compiled vdl file.
func (*File) DeclareIdent ¶
DeclareIdent declares ident with the given detail string. Returns an error if ident conflicts with an existing identifier in this file or package, where the error includes the the previous declaration detail.
func (*File) LookupImportPath ¶
LookupImportPath translates local into a package path name, based on the imports associated with the file. Returns the empty string "" if local couldn't be found; every valid package path is non-empty.
func (*File) ValidateImportPackagePath ¶
ValidateImportPackagePath returns true iff path is listed in the file's imports, and marks the import as used.
type Interface ¶
type Interface struct { NamePos // interface name, pos and doc Exported bool // is this interface exported? Embeds []*Interface // list of embedded interfaces Methods []*Method // list of methods File *File // parent file }
Interface represents a set of embedded interfaces and methods.
func (*Interface) AllMethods ¶
func (*Interface) FindMethod ¶
func (*Interface) TransitiveEmbeds ¶
type LangFmt ¶
type LangFmt struct { Lang i18n.LangID // IETF language tag Fmt string // i18n format string in the given language. }
LangFmt represents a language / format string pair.
type Method ¶
type Method struct { NamePos // method name, pos and doc InArgs []*Field // list of positional in-args OutArgs []*Field // list of positional out-args InStream *vdl.Type // in-stream type, may be nil OutStream *vdl.Type // out-stream type, may be nil Tags []*vdl.Value // list of method tags Interface *Interface // parent interface }
Method represents a method in an interface.
type Package ¶
type Package struct { // Name is the name of the package, specified in the vdl files. // E.g. "bar" Name string // Path is the package path; the path used in VDL import clauses. // E.g. "foo/bar". Path string // GenPath is the package path to use for code generation. It is typically // the same as Path, except for vdlroot standard packages. // E.g. "v.io/v23/vdlroot/time" GenPath string // Files holds the files contained in the package. Files []*File // FileDoc holds the top-level file documentation, which must be the same for // every file in the package. This is typically used to hold boilerplate that // must appear in every generated file, e.g. a copyright notice. FileDoc string // Config holds the configuration for this package, specifying options used // during compilation and code generation. Config vdltool.Config // contains filtered or unexported fields }
Package represents a vdl package, containing a list of files.
func CompilePackage ¶
func CompilePackage(pkgpath, genpath string, pfiles []*parse.File, config vdltool.Config, env *Env) *Package
CompilePackage compiles a list of parse.Files into a Package. Updates env with the compiled package and returns it on success, or returns nil and guarantees !env.Errors.IsEmpty(). All imports that the parsed package depend on must already have been compiled and populated into env.
func (*Package) ConstDefs ¶
ConstDefs returns all consts defined in this package, in dependency order. If const B refers to const A, B depends on A, and A will appear before B. Consts cannot have cyclic dependencies.
func (*Package) Doc ¶
Doc returns the package documentation, which should only exist in a single file in the package.
func (*Package) ErrorDefs ¶
ErrorDefs returns all errors defined in this package. Errors don't have dependencies.
func (*Package) Interfaces ¶
Interfaces returns all interfaces defined in this package, in dependency order. If interface B embeds interface A, B depends on A, and A will appear before B. Interfaces cannot have cyclic dependencies.
func (*Package) QualifiedName ¶
QualifiedName returns the fully-qualified name of an identifier, by prepending the identifier with the package path.
func (*Package) ResolveConst ¶
ResolveConst resolves the const name to its definition.
func (*Package) ResolveInterface ¶
ResolveInterface resolves the interface name to its definition.
func (*Package) ResolveType ¶
ResolveType resolves the type name to its definition.
type TypeDef ¶
type TypeDef struct { NamePos // name, parse position and docs Exported bool // is this type definition exported? Type *vdl.Type // type of this type definition // BaseType is the type that Type is based on. The BaseType may be named or // unnamed. E.g. // BaseType // type Bool bool; bool // type Bool2 Bool; Bool // type List []int32; []int32 // type List2 List; List // type Struct struct{A bool}; struct{A bool} // type Struct2 Struct; Struct BaseType *vdl.Type LabelDoc []string // [valid for enum] docs for each label LabelDocSuffix []string // [valid for enum] suffix docs for each label FieldDoc []string // [valid for struct, union] docs for each field FieldDocSuffix []string // [valid for struct, union] suffix docs for each field File *File // parent file that this type is defined in }
TypeDef represents a user-defined named type definition in the compiled results.