v.io: v.io/x/ref/lib/vdl/compile Index | Files

package compile

import "v.io/x/ref/lib/vdl/compile"

Package compile implements the VDL compiler, converting a parse tree into compiled results. The CompilePackage function is the main entry point.

Index

Package Files

builtin.go compile.go const.go error.go interface.go reserved_words.go result.go type.go

Variables

var (
    // BuiltInPackage and BuiltInFile are used to hold the built-ins.
    BuiltInPackage = newPackage("", "_builtin", "_builtin", vdltool.Config{})
    BuiltInFile    = &File{BaseName: "_builtin.vdl"}
)
var (
    // NilConst is defined by the compiler, as are TrueConst and FalseConst.
    NilConst   = vdl.ZeroValue(vdl.AnyType) // nil == any(nil)
    TrueConst  = vdl.BoolValue(nil, true)
    FalseConst = vdl.BoolValue(nil, false)
)

func CompileConfig Uses

func CompileConfig(t *vdl.Type, pconfig *parse.Config, env *Env) *vdl.Value

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. nolint:golint // API change required.

func CompileExpr Uses

func CompileExpr(t *vdl.Type, expr parse.ConstExpr, env *Env) *vdl.Value

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. nolint:golint // API change required.

type ConstDef Uses

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.

func (*ConstDef) String Uses

func (x *ConstDef) String() string

type Env Uses

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 NewEnv Uses

func NewEnv(maxErrors int) *Env

NewEnv creates a new Env, allowing up to maxErrors errors before we stop.

func NewEnvWithErrors Uses

func NewEnvWithErrors(errs, warnings *vdlutil.Errors) *Env

NewEnvWithErrors creates a new Env, using the given errs to collect errors.

func (*Env) DisallowI18nErrorSupport Uses

func (e *Env) DisallowI18nErrorSupport() *Env

DisallowI18nErrorSupport disables i18n formats for errors.

func (*Env) DisallowPathQualifiers Uses

func (e *Env) DisallowPathQualifiers() *Env

DisallowPathQualifiers disables syntax like "a/b/c".Type.

func (*Env) ErrorI18nSupport Uses

func (e *Env) ErrorI18nSupport() bool

ErrorI18nSupport returns true if i18n support is enabled for errors.

func (*Env) Errorf Uses

func (e *Env) Errorf(file *File, pos parse.Pos, format string, v ...interface{})

Errorf is a helper for error reporting, to consistently contain the file and position of the error when possible.

func (*Env) EvalConst Uses

func (e *Env) EvalConst(name string, file *File) (opconst.Const, error)

EvalConst resolves and evaluates a name to a const.

func (*Env) FindConstDef Uses

func (e *Env) FindConstDef(v *vdl.Value) *ConstDef

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 Uses

func (e *Env) FindTypeDef(t *vdl.Type) *TypeDef

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 Uses

func (e *Env) ResolveConst(name string, file *File) (cd *ConstDef, matched string)

ResolveConst resolves a name to a const definition. Returns the const def and the portion of name that was matched.

func (*Env) ResolveInterface Uses

func (e *Env) ResolveInterface(name string, file *File) (i *Interface, matched string)

ResolveInterface resolves a name to an interface definition. Returns the interface and the portion of name that was matched.

func (*Env) ResolvePackage Uses

func (e *Env) ResolvePackage(path string) *Package

ResolvePackage resolves a package path to its previous compiled results.

func (*Env) ResolvePackageGenPath Uses

func (e *Env) ResolvePackageGenPath(genPath string) *Package

ResolvePackageGenPath resolves a package gen path to its previous compiled results.

func (*Env) ResolveType Uses

func (e *Env) ResolveType(name string, file *File) (td *TypeDef, matched string)

ResolveType resolves a name to a type definition. Returns the type def and the portion of name that was matched.

func (*Env) Warningf Uses

func (e *Env) Warningf(file *File, pos parse.Pos, format string, v ...interface{})

Warningf is like errorf but for warning messages that will not cause the compilation to fail.

type ErrorDef Uses

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.

func (*ErrorDef) String Uses

func (x *ErrorDef) String() string

type Field Uses

type Field struct {
    NamePos           // arg name, pos and doc
    Type    *vdl.Type // arg type, never nil
}

Field represents method arguments and error params.

func (*Field) String Uses

func (x *Field) String() string

type File Uses

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 Uses

func (f *File) DeclareIdent(ident, detail string) error

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 Uses

func (f *File) LookupImportPath(local string) string

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) String Uses

func (f *File) String() string

func (*File) ValidateImportPackagePath Uses

func (f *File) ValidateImportPackagePath(path string) bool

ValidateImportPackagePath returns true iff path is listed in the file's imports, and marks the import as used.

type Interface Uses

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 Uses

func (x *Interface) AllMethods() []*Method

func (*Interface) FindMethod Uses

func (x *Interface) FindMethod(name string) *Method

func (*Interface) String Uses

func (x *Interface) String() string

func (*Interface) TransitiveEmbeds Uses

func (x *Interface) TransitiveEmbeds() []*Interface

type LangFmt Uses

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 Uses

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.

func (*Method) String Uses

func (x *Method) String() string

type NamePos Uses

type NamePos parse.NamePos

NamePos represents a name, its associated position and documentation.

func (*NamePos) String Uses

func (x *NamePos) String() string

type Package Uses

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 Uses

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. nolint:golint // API change required.

func (*Package) ConstDefs Uses

func (p *Package) ConstDefs() (x []*ConstDef)

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 Uses

func (p *Package) Doc() string

Doc returns the package documentation, which should only exist in a single file in the package.

func (*Package) ErrorDefs Uses

func (p *Package) ErrorDefs() (x []*ErrorDef)

ErrorDefs returns all errors defined in this package. Errors don't have dependencies.

func (*Package) Interfaces Uses

func (p *Package) Interfaces() (x []*Interface)

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 Uses

func (p *Package) QualifiedName(id string) string

QualifiedName returns the fully-qualified name of an identifier, by prepending the identifier with the package path.

func (*Package) ResolveConst Uses

func (p *Package) ResolveConst(name string) *ConstDef

ResolveConst resolves the const name to its definition.

func (*Package) ResolveInterface Uses

func (p *Package) ResolveInterface(name string) *Interface

ResolveInterface resolves the interface name to its definition.

func (*Package) ResolveType Uses

func (p *Package) ResolveType(name string) *TypeDef

ResolveType resolves the type name to its definition.

func (*Package) String Uses

func (p *Package) String() string

func (*Package) TypeDefs Uses

func (p *Package) TypeDefs() []*TypeDef

TypeDefs returns all types defined in this package, in dependency order. If type B refers to type A, B depends on A, and A will appear before B. Types may have cyclic dependencies; the ordering of cyclicly dependent types is arbitrary.

type TypeDef Uses

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.

func (*TypeDef) String Uses

func (x *TypeDef) String() string

Package compile imports 16 packages (graph) and is imported by 15 packages. Updated 2020-10-22. Refresh now. Tools for package owners.