Documentation ¶
Overview ¶
Package ir defines an intermediate representation (IR) for Rego.
The IR specifies an imperative execution model for Rego policies similar to a query plan in traditional databases.
Index ¶
- Constants
- func Pretty(w io.Writer, x interface{})
- func Walk(vis Visitor, x interface{}) error
- type ArrayAppendStmt
- type AssignBooleanStmt
- type AssignIntStmt
- type AssignVarOnceStmt
- type AssignVarStmt
- type Block
- type BlockStmt
- type BooleanConst
- type BreakStmt
- type CallStmt
- type Const
- type DotStmt
- type EqualStmt
- type FloatConst
- type Func
- type Funcs
- type GreaterThanEqualStmt
- type GreaterThanStmt
- type IntConst
- type IsArrayStmt
- type IsDefinedStmt
- type IsObjectStmt
- type IsUndefinedStmt
- type LenStmt
- type LessThanEqualStmt
- type LessThanStmt
- type Local
- type MakeArrayStmt
- type MakeBooleanStmt
- type MakeNullStmt
- type MakeNumberIntStmt
- type MakeObjectStmt
- type MakeSetStmt
- type MakeStringStmt
- type NotEqualStmt
- type NotStmt
- type NullConst
- type ObjectInsertOnceStmt
- type ObjectInsertStmt
- type Plan
- type Policy
- type ReturnLocalStmt
- type ReturnStmt
- type ScanStmt
- type SetAddStmt
- type Static
- type Stmt
- type StringConst
- type Visitor
Constants ¶
const ( // Undefined represents an undefined return value. An undefined return value // indicates the policy did not return a definitive answer. Undefined int32 = iota // Defined represents a defined return value. Defined // Error indicates a runtime error occurred during evaluation. Error )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ArrayAppendStmt ¶ added in v0.10.3
ArrayAppendStmt represents a dynamic append operation of a value onto an array.
type AssignBooleanStmt ¶ added in v0.10.3
AssignBooleanStmt represents an assignment of a boolean value to a local variable.
type AssignIntStmt ¶ added in v0.10.3
AssignIntStmt represents an assignment of an integer value to a local variable.
type AssignVarOnceStmt ¶ added in v0.11.0
AssignVarOnceStmt represents an assignment of one local variable to another. If the target is defined, execution aborts with a conflict error.
TODO(tsandall): is there a better name for this?
type AssignVarStmt ¶ added in v0.10.3
AssignVarStmt represents an assignment of one local variable to another.
type Block ¶
type Block struct {
Stmts []Stmt
}
Block represents an ordered sequence of statements to execute. Blocks are executed until a return statement is encountered, a statement is undefined, or there are no more statements. If all statements are defined but no return statement is encountered, the block is undefined.
type BlockStmt ¶ added in v0.11.0
type BlockStmt struct {
Blocks []*Block
}
BlockStmt represents a nested block. Nested blocks and break statements can be used to short-circuit execution.
type BooleanConst ¶
type BooleanConst struct {
Value bool
}
BooleanConst represents a boolean value.
type BreakStmt ¶ added in v0.11.0
type BreakStmt struct {
Index uint32
}
BreakStmt represents a jump out of the current block. The index specifies how many blocks to jump starting from zero (the current block). Execution will continue from the end of the block that is jumped to.
type CallStmt ¶ added in v0.11.0
CallStmt represents a named function call. The result should be stored in the result local.
type Const ¶ added in v0.10.2
type Const interface {
// contains filtered or unexported methods
}
Const represents a constant value from the policy.
type DotStmt ¶
DotStmt represents a lookup operation on a value (e.g., array, object, etc.) The source of a DotStmt may be a scalar value in which case the statement will be undefined.
type FloatConst ¶
type FloatConst struct {
Value float64
}
FloatConst represents a floating-point constant.
type Func ¶ added in v0.11.0
type Func struct { Name string Params []Local Return Local Blocks []*Block // TODO(tsandall): should this be a plan? }
Func represents a named plan (function) that can be invoked. Functions accept one or more parameters and return a value. By convention, the input document is always passed as the first argument.
type Funcs ¶ added in v0.11.0
Funcs represents a collection of planned functions to include in the policy.
type GreaterThanEqualStmt ¶
GreaterThanEqualStmt represents a >= check of two local variables.
type GreaterThanStmt ¶
GreaterThanStmt represents a > check of two local variables.
type IsArrayStmt ¶ added in v0.10.3
type IsArrayStmt struct {
Source Local
}
IsArrayStmt represents a dynamic type check on a local variable.
type IsDefinedStmt ¶ added in v0.11.0
type IsDefinedStmt struct {
Source Local
}
IsDefinedStmt represents a check of whether a local variable is defined.
type IsObjectStmt ¶ added in v0.10.3
type IsObjectStmt struct {
Source Local
}
IsObjectStmt represents a dynamic type check on a local variable.
type IsUndefinedStmt ¶ added in v0.11.0
type IsUndefinedStmt struct {
Source Local
}
IsUndefinedStmt represents a check of whether local variable is undefined.
type LenStmt ¶ added in v0.10.3
LenStmt represents a length() operation on a local variable. The result is stored in the target local variable.
type LessThanEqualStmt ¶
LessThanEqualStmt represents a <= check of two local variables.
type LessThanStmt ¶
LessThanStmt represents a < check of two local variables.
type Local ¶
type Local int
Local represents a plan-scoped variable.
TODO(tsandall): should this be int32 for safety?
const ( // InputRaw refers to the local variable containing the address of the raw // (serialized) input data. InputRaw Local = 0 // InputLen refers to the local variable containing the length of the raw input. InputLen Local = 1 // Input refers to the local variable containing the address of the deserialized // input value. Input Local = 2 )
type MakeArrayStmt ¶ added in v0.10.3
MakeArrayStmt constructs a local variable that refers to an array value.
type MakeBooleanStmt ¶
MakeBooleanStmt constructs a local variable that refers to a boolean value.
type MakeNullStmt ¶ added in v0.10.3
type MakeNullStmt struct {
Target Local
}
MakeNullStmt constructs a local variable that refers to a null value.
type MakeNumberIntStmt ¶
MakeNumberIntStmt constructs a local variable that refers to an integer value.
type MakeObjectStmt ¶ added in v0.10.3
type MakeObjectStmt struct {
Target Local
}
MakeObjectStmt constructs a local variable that refers to an object value.
type MakeSetStmt ¶ added in v0.11.0
type MakeSetStmt struct {
Target Local
}
MakeSetStmt constructs a local variable that refers to a set value.
type MakeStringStmt ¶
MakeStringStmt constructs a local variable that refers to a string constant.
type NotEqualStmt ¶
NotEqualStmt represents a != check of two local variables.
type NotStmt ¶ added in v0.10.3
NotStmt represents a negated statement. The last statement in the negation block will set the condition to false.
type ObjectInsertOnceStmt ¶ added in v0.11.0
ObjectInsertOnceStmt represents a dynamic insert operation of a key/value pair into an object. If the key already exists and the value differs, execution aborts with a conflict error.
type ObjectInsertStmt ¶ added in v0.10.3
ObjectInsertStmt represents a dynamic insert operation of a key/value pair into an object.
type Plan ¶
type Plan struct {
Blocks []*Block
}
Plan represents an ordered series of blocks to execute. All plans contain a final block that returns indicating the plan result was undefined. Plan execution stops when a block returns a value. Blocks are executed in-order.
type ReturnLocalStmt ¶ added in v0.11.0
type ReturnLocalStmt struct {
Source Local
}
ReturnLocalStmt represents a return statement that yields a local value.
type ReturnStmt ¶
type ReturnStmt struct {
Code int32 // 32-bit integer for compatibility with languages like JavaScript.
}
ReturnStmt represents a return statement. Return statements halt execution of a plan with the given code.
type ScanStmt ¶ added in v0.10.3
ScanStmt represents a linear scan over a composite value. The source may be a scalar in which case the block will never execute.
type SetAddStmt ¶ added in v0.11.0
SetAddStmt represents a dynamic add operation of an element into a set.
type Static ¶
type Static struct {
Strings []*StringConst
}
Static represents a static data segment that is indexed into by the policy.