compile

package
v0.0.0-...-2e60efa Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: BSD-3-Clause, MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCapsLocation = "/config/features"
View Source
const SystemCapsLocation = "/opt/vyatta/etc/features"

TODO: We should make this able to be configured. We are currently under a crunch, so doing this for now. This location is non-user changeable so only non-shipped features can be toggled.

Variables

This section is empty.

Functions

func CompileDir

func CompileDir(extensions Extensions, cfg *Config,
) (schema.ModelSet, error,
)

func CompileDirKeepMods

func CompileDirKeepMods(extensions Extensions, cfg *Config,
) (schema.ModelSet, error, map[string]*parse.Module, map[string]*parse.Module,
)

func CompileDirWithWarnings

func CompileDirWithWarnings(extensions Extensions, cfg *Config,
) (schema.ModelSet, []xutils.Warning, error,
)

func CompileModules

func CompileModules(
	extensions Extensions,
	mods map[string]*parse.Tree,
	features string,
	skipUnknown bool,
	filter SchemaFilter,
) (schema.ModelSet, error)

func CompileModulesWithWarnings

func CompileModulesWithWarnings(
	extensions Extensions,
	mods map[string]*parse.Tree,
	features string,
	skipUnknown bool,
	filter SchemaFilter,
) (schema.ModelSet, []xutils.Warning, error)

func CompileModulesWithWarningsAndCustomFunctions

func CompileModulesWithWarningsAndCustomFunctions(
	extensions Extensions,
	mods map[string]*parse.Tree,
	features string,
	skipUnknown bool,
	filter SchemaFilter,
	userFnChecker xpath.UserCustomFunctionCheckerFn,
) (schema.ModelSet, []xutils.Warning, error)

func CompileParseTrees

func CompileParseTrees(
	extensions Extensions,
	mods map[string]*parse.Tree,
	features FeaturesChecker,
	skipUnknown bool,
	filter SchemaFilter,
) (schema.ModelSet, error)

func DisableCompilerDebug

func DisableCompilerDebug()

func EnableCompilerDebug

func EnableCompilerDebug()

func IsConfig

func IsConfig(sn schema.Node) bool

Filter configuration nodes

func IsOpd

func IsOpd(sn schema.Node) bool

Filter opd: extension nodes

func IsState

func IsState(sn schema.Node) bool

Filter operational state nodes, which are config false

func ParseModuleDir

func ParseModuleDir(dir string, extCard parse.NodeCardinality) (map[string]*parse.Tree, error)

func ParseModules

func ParseModules(extCard parse.NodeCardinality, list ...string) (map[string]*parse.Tree, error)

func ParseYang

func ParseYang(extCard parse.NodeCardinality, locator YangLocator) (map[string]*parse.Tree, error)

func YangModulesFromDir

func YangModulesFromDir(dir string) ([]string, error)

Types

type Compiler

type Compiler struct {
	// contains filtered or unexported fields
}

func NewCompiler

func NewCompiler(
	extensions Extensions,
	modules map[string]*parse.Module,
	submodules map[string]*parse.Module,
	features FeaturesChecker,
	skipUnknown, generateWarnings bool,
	filter SchemaFilter,
) *Compiler

func (*Compiler) BuildBaseType

func (c *Compiler) BuildBaseType(
	cfgNode parse.Node,
	typ parse.Node,
	def string,
	hasDef bool,
	parentStatus schema.Status,
) (schema.Type, xml.Name, bool)

func (*Compiler) BuildCase

func (c *Compiler) BuildCase(features inheritedFeatures, m parse.Node, n parse.Node) schema.Node

func (*Compiler) BuildChoice

func (c *Compiler) BuildChoice(features inheritedFeatures, m parse.Node, n parse.Node) schema.Node

func (*Compiler) BuildContainer

func (c *Compiler) BuildContainer(features inheritedFeatures, m parse.Node, n parse.Node) schema.Node

func (*Compiler) BuildLeaf

func (comp *Compiler) BuildLeaf(
	features inheritedFeatures,
	mod parse.Node,
	node parse.Node,
	isKey bool,
) schema.Node

func (*Compiler) BuildLeafList

func (c *Compiler) BuildLeafList(features inheritedFeatures, m parse.Node, n parse.Node) schema.Node

func (*Compiler) BuildList

func (c *Compiler) BuildList(features inheritedFeatures, m parse.Node, n parse.Node) schema.Node

func (*Compiler) BuildModule

func (c *Compiler) BuildModule(module *parse.Module, m parse.Node) schema.Model

func (*Compiler) BuildModules

func (c *Compiler) BuildModules() (modules map[string]schema.Model, err error)

func (*Compiler) BuildMusts

func (c *Compiler) BuildMusts(n parse.Node) []schema.MustContext

func (*Compiler) BuildNode

func (c *Compiler) BuildNode(
	inherited inheritedFeatures,
	m parse.Node,
	n parse.Node,
	isKey bool,
) (retNodes []schema.Node)

func (*Compiler) BuildOpdArgument

func (c *Compiler) BuildOpdArgument(
	features inheritedFeatures,
	mod parse.Node,
	node parse.Node,
) schema.Node

func (*Compiler) BuildOpdCommand

func (c *Compiler) BuildOpdCommand(features inheritedFeatures, m parse.Node, n parse.Node) schema.Node

func (*Compiler) BuildOpdOption

func (c *Compiler) BuildOpdOption(
	features inheritedFeatures,
	mod parse.Node,
	node parse.Node,
) schema.Node

func (*Compiler) BuildType

func (c *Compiler) BuildType(
	cfgNode parse.Node,
	typ parse.Node,
	def string,
	hasDef bool,
	parentStatus schema.Status,
) schema.Type

This recursively works down a chain of type / typedefs until it gets to the base type. It then builds the base type, checking range. Then we work back up, refining the type as we go if it's a typedef type.

We also set the default, if specified, and pass it up. At each level, a new default overrides an existing one, otherwise we inherit the default, if it exists.

Cannot have default and mandatory - unclear how we will check if default is inherited.

func (*Compiler) BuildWhens

func (c *Compiler) BuildWhens(n parse.Node) []schema.WhenContext

func (*Compiler) CheckChildren

func (c *Compiler) CheckChildren(m parse.Node, n parse.Node)

func (*Compiler) CheckIfFeature

func (c *Compiler) CheckIfFeature(n parse.Node, parentStatus schema.Status) bool

Verify that an if-feature reference is valid, and determine if the referenced feature is enabled A referenced feature takes the form [prefix:]feature-name If no prefix is present, it is an implicit reference to the local module.

func (*Compiler) CheckMinMax

func (c *Compiler) CheckMinMax(n parse.Node, min, max uint)

func (*Compiler) CheckUniqueConstraint

func (c *Compiler) CheckUniqueConstraint(m parse.Node, n parse.Node)

unique-arg cannot traverse a descedant list (see https://www.ietf.org/mail-archive/web/netmod/current/msg06386.html)

func (*Compiler) CheckUnknown

func (c *Compiler) CheckUnknown(m parse.Node, n parse.Node)

func (*Compiler) ExpandModules

func (c *Compiler) ExpandModules() (err error)

func (*Compiler) IgnoreNode

func (c *Compiler) IgnoreNode(node parse.Node, parentStatus schema.Status) bool

func (*Compiler) ProcessModuleIncludes

func (c *Compiler) ProcessModuleIncludes(m parse.Node, submodules map[string]parse.Node)

func (*Compiler) ProcessSubmoduleIncludes

func (c *Compiler) ProcessSubmoduleIncludes(m parse.Node, submodules map[string]parse.Node)

func (*Compiler) VerifyModuleIncludes

func (c *Compiler) VerifyModuleIncludes(m parse.Node, submodules map[string]parse.Node)

type Config

type Config struct {
	YangDir       string
	YangLocations YangLocator
	CapsLocation  string
	Features      FeaturesChecker
	SkipUnknown   bool
	Filter        SchemaFilter
	// Used for the likes of yangc to inject names of valid custom functions
	// that otherwise would not be visible to the compiler.  Only used during
	// path evaluation.
	UserFnCheckFn xpath.UserCustomFunctionCheckerFn
}

type Extensions

type Extensions interface {

	// Returns a function used to get the cardinality of any extension
	NodeCardinality(parse.NodeType) map[parse.NodeType]parse.Cardinality

	// Extend the complete model set, including the combined tree of
	// all the underlying models
	ExtendModelSet(schema.ModelSet) (schema.ModelSet, error)

	// Extend the schema tree used for RPC parameters and schema Models
	ExtendModel(parse.Node, schema.Model, schema.Tree) (schema.Model, error)

	// Extend the RPC node which includes input and output parameters
	// as trees
	ExtendRpc(parse.Node, schema.Rpc) (schema.Rpc, error)

	// Extend the Notification node
	ExtendNotification(parse.Node, schema.Notification) (schema.Notification, error)

	// Extend the schema tree used for RPC parameters and schema Models
	ExtendTree(parse.Node, schema.Tree) (schema.Tree, error)

	// Extend the various nodes within a schema Tree
	ExtendContainer(parse.Node, schema.Container) (schema.Container, error)
	ExtendList(parse.Node, schema.List) (schema.List, error)
	ExtendLeaf(parse.Node, schema.Leaf) (schema.Leaf, error)
	ExtendLeafList(parse.Node, schema.LeafList) (schema.LeafList, error)

	// Extend choice and case nodes
	ExtendChoice(parse.Node, schema.Choice) (schema.Choice, error)
	ExtendCase(parse.Node, schema.Case) (schema.Case, error)

	// Extend the type, given the parse node and the base type that this
	// type is derived from. The base time may be nil, when the type is
	// a built in type.
	ExtendType(p parse.Node, base schema.Type, t schema.Type) (schema.Type, error)
	// Extend must to allow for custom must optimisations
	ExtendMust(p parse.Node, m parse.Node) (string, error)

	ExtendOpdCommand(parse.Node, schema.OpdCommand) (schema.OpdCommand, error)
	ExtendOpdOption(parse.Node, schema.OpdOption) (schema.OpdOption, error)
	ExtendOpdArgument(parse.Node, schema.OpdArgument) (schema.OpdArgument, error)
}

* To add extensions to the schema tree a simple pattern is followed. * The compiler turns a set of parse nodes into a schema node. As each * node is compiled, it is passed to the extensions which are given an * opportunity to wrap (decorate) the node with any extensions. If * the extensions are misused then an error may be returned instead.

type FeatureStatus

type FeatureStatus int
const (
	DISABLED FeatureStatus = iota
	ENABLED
	NOTPRESENT
)

func StatusFromBool

func StatusFromBool(b bool) FeatureStatus

func (FeatureStatus) String

func (f FeatureStatus) String() string

type FeaturesChecker

type FeaturesChecker interface {
	Status(feature string) FeatureStatus
}

FeaturesChecker checks the status of a feature feature is formatted <module>:<feature name>

func FeaturesFromLocations

func FeaturesFromLocations(enabled bool, locations ...string) FeaturesChecker

func FeaturesFromNames

func FeaturesFromNames(enabled bool, features ...string) FeaturesChecker

func MultiFeatureCheckers

func MultiFeatureCheckers(f ...FeaturesChecker) FeaturesChecker

type SchemaFilter

type SchemaFilter func(sn schema.Node) bool

func Exclude

func Exclude(filters ...SchemaFilter) SchemaFilter

Returns a filter which will exclude nodes that match a set of filters

func Include

func Include(filters ...SchemaFilter) SchemaFilter

Returns a filter which will include nodes that match a set of filters

func IncludeState

func IncludeState(state bool) SchemaFilter

Returns an operational state node filter if state is true

func IsConfigOrState

func IsConfigOrState() SchemaFilter

Filter configuration and operational state nodes

type SchemaType

type SchemaType int
const (
	SchemaBool SchemaType = iota
	SchemaEmpty
	SchemaEnumeration
	SchemaIdentity
	SchemaInstanceId
	SchemaNumber
	SchemaDecimal64
	SchemaString
	SchemaUnion
	SchemaBits
	SchemaLeafRef
)

type YangLocator

type YangLocator func() ([]string, error)

func YangDirs

func YangDirs(dirs ...string) YangLocator

func YangFiles

func YangFiles(files ...string) YangLocator

func YangLocations

func YangLocations(locations ...YangLocator) YangLocator

Jump to

Keyboard shortcuts

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