opa: github.com/open-policy-agent/opa/internal/ir Index | Files

package ir

import "github.com/open-policy-agent/opa/internal/ir"

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

Package Files

ir.go pretty.go walk.go

func Pretty Uses

func Pretty(w io.Writer, x interface{})

Pretty writes a human-readable representation of an IR object to w.

func Walk Uses

func Walk(vis Visitor, x interface{}) error

Walk invokes the visitor for nodes under x.

type ArrayAppendStmt Uses

type ArrayAppendStmt struct {
    Value Local
    Array Local
}

ArrayAppendStmt represents a dynamic append operation of a value onto an array.

type AssignBooleanStmt Uses

type AssignBooleanStmt struct {
    Value  bool
    Target Local
}

AssignBooleanStmt represents an assignment of a boolean value to a local variable.

type AssignIntStmt Uses

type AssignIntStmt struct {
    Value  int64
    Target Local
}

AssignIntStmt represents an assignment of an integer value to a local variable.

type AssignVarOnceStmt Uses

type AssignVarOnceStmt struct {
    Target Local
    Source Local
}

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 Uses

type AssignVarStmt struct {
    Source Local
    Target Local
}

AssignVarStmt represents an assignment of one local variable to another.

type Block Uses

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.

func (*Block) String Uses

func (a *Block) String() string

type BlockStmt Uses

type BlockStmt struct {
    Blocks []*Block
}

BlockStmt represents a nested block. Nested blocks and break statements can be used to short-circuit execution.

func (*BlockStmt) String Uses

func (a *BlockStmt) String() string

type BooleanConst Uses

type BooleanConst struct {
    Value bool
}

BooleanConst represents a boolean value.

type BreakStmt Uses

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

type BuiltinFunc struct {
    Name string
}

BuiltinFunc represents a built-in function that may be required by the policy.

type CallStmt Uses

type CallStmt struct {
    Func   string
    Args   []Local
    Result Local
}

CallStmt represents a named function call. The result should be stored in the result local.

type Const Uses

type Const interface {
    // contains filtered or unexported methods
}

Const represents a constant value from the policy.

type DotStmt Uses

type DotStmt struct {
    Source Local
    Key    Local
    Target Local
}

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

type EqualStmt struct {
    A   Local
    B   Local
}

EqualStmt represents an value-equality check of two local variables.

type FloatConst Uses

type FloatConst struct {
    Value float64
}

FloatConst represents a floating-point constant.

type Func Uses

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 and data documents are always passed as the first and second arguments (respectively).

func (*Func) String Uses

func (a *Func) String() string

type Funcs Uses

type Funcs struct {
    Funcs []*Func
}

Funcs represents a collection of planned functions to include in the policy.

func (*Funcs) String Uses

func (a *Funcs) String() string

type GreaterThanEqualStmt Uses

type GreaterThanEqualStmt struct {
    A   Local
    B   Local
}

GreaterThanEqualStmt represents a >= check of two local variables.

type GreaterThanStmt Uses

type GreaterThanStmt struct {
    A   Local
    B   Local
}

GreaterThanStmt represents a > check of two local variables.

type IntConst Uses

type IntConst struct {
    Value int64
}

IntConst represents an integer constant.

type IsArrayStmt Uses

type IsArrayStmt struct {
    Source Local
}

IsArrayStmt represents a dynamic type check on a local variable.

type IsDefinedStmt Uses

type IsDefinedStmt struct {
    Source Local
}

IsDefinedStmt represents a check of whether a local variable is defined.

type IsObjectStmt Uses

type IsObjectStmt struct {
    Source Local
}

IsObjectStmt represents a dynamic type check on a local variable.

type IsUndefinedStmt Uses

type IsUndefinedStmt struct {
    Source Local
}

IsUndefinedStmt represents a check of whether local variable is undefined.

type LenStmt Uses

type LenStmt struct {
    Source Local
    Target Local
}

LenStmt represents a length() operation on a local variable. The result is stored in the target local variable.

type LessThanEqualStmt Uses

type LessThanEqualStmt struct {
    A   Local
    B   Local
}

LessThanEqualStmt represents a <= check of two local variables.

type LessThanStmt Uses

type LessThanStmt struct {
    A   Local
    B   Local
}

LessThanStmt represents a < check of two local variables.

type Local Uses

type Local int

Local represents a plan-scoped variable.

TODO(tsandall): should this be int32 for safety?

const (
    // Input is the local variable that refers to the global input document.
    Input Local = iota

    // Data is the local variable that refers to the global data document.
    Data

    // Unused is the free local variable that can be allocated in a plan.
    Unused
)

type MakeArrayStmt Uses

type MakeArrayStmt struct {
    Capacity int32
    Target   Local
}

MakeArrayStmt constructs a local variable that refers to an array value.

type MakeBooleanStmt Uses

type MakeBooleanStmt struct {
    Value  bool
    Target Local
}

MakeBooleanStmt constructs a local variable that refers to a boolean value.

type MakeNullStmt Uses

type MakeNullStmt struct {
    Target Local
}

MakeNullStmt constructs a local variable that refers to a null value.

type MakeNumberFloatStmt Uses

type MakeNumberFloatStmt struct {
    Value  float64
    Target Local
}

MakeNumberFloatStmt constructs a local variable that refers to a floating-point number value.

type MakeNumberIntStmt Uses

type MakeNumberIntStmt struct {
    Value  int64
    Target Local
}

MakeNumberIntStmt constructs a local variable that refers to an integer value.

type MakeNumberRefStmt Uses

type MakeNumberRefStmt struct {
    Index  int
    Target Local
}

MakeNumberRefStmt constructs a local variable that refers to a number stored as a string.

type MakeObjectStmt Uses

type MakeObjectStmt struct {
    Target Local
}

MakeObjectStmt constructs a local variable that refers to an object value.

type MakeSetStmt Uses

type MakeSetStmt struct {
    Target Local
}

MakeSetStmt constructs a local variable that refers to a set value.

type MakeStringStmt Uses

type MakeStringStmt struct {
    Index  int
    Target Local
}

MakeStringStmt constructs a local variable that refers to a string constant.

type NotEqualStmt Uses

type NotEqualStmt struct {
    A   Local
    B   Local
}

NotEqualStmt represents a != check of two local variables.

type NotStmt Uses

type NotStmt struct {
    Block *Block
}

NotStmt represents a negated statement.

type NullConst Uses

type NullConst struct{}

NullConst represents a null value.

type ObjectInsertOnceStmt Uses

type ObjectInsertOnceStmt struct {
    Key    Local
    Value  Local
    Object Local
}

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 Uses

type ObjectInsertStmt struct {
    Key    Local
    Value  Local
    Object Local
}

ObjectInsertStmt represents a dynamic insert operation of a key/value pair into an object.

type ObjectMergeStmt Uses

type ObjectMergeStmt struct {
    A      Local
    B      Local
    Target Local
}

ObjectMergeStmt performs a recursive merge of two object values. If either of the locals refer to non-object values this operation will abort with a conflict error. Overlapping object keys are merged recursively.

type Plan Uses

type Plan struct {
    Blocks []*Block
}

Plan represents an ordered series of blocks to execute. Plan execution stops when a return statement is reached. Blocks are executed in-order.

func (*Plan) String Uses

func (a *Plan) String() string

type Policy Uses

type Policy struct {
    Static *Static
    Plan   *Plan
    Funcs  *Funcs
}

Policy represents a planned policy query.

func (*Policy) String Uses

func (a *Policy) String() string

type ResultSetAdd Uses

type ResultSetAdd struct {
    Value Local
}

ResultSetAdd adds a value into the result set returned by the query plan.

type ReturnLocalStmt Uses

type ReturnLocalStmt struct {
    Source Local
}

ReturnLocalStmt represents a return statement that yields a local value.

type ScanStmt Uses

type ScanStmt struct {
    Source Local
    Key    Local
    Value  Local
    Block  *Block
}

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 Uses

type SetAddStmt struct {
    Value Local
    Set   Local
}

SetAddStmt represents a dynamic add operation of an element into a set.

type Static Uses

type Static struct {
    Strings      []*StringConst
    BuiltinFuncs []*BuiltinFunc
}

Static represents a static data segment that is indexed into by the policy.

func (*Static) String Uses

func (a *Static) String() string

type Stmt Uses

type Stmt interface {
}

Stmt represents an operation (e.g., comparison, loop, dot, etc.) to execute.

type StringConst Uses

type StringConst struct {
    Value string
}

StringConst represents a string value.

type Visitor Uses

type Visitor interface {
    Before(x interface{})
    Visit(x interface{}) (Visitor, error)
    After(x interface{})
}

Visitor defines the interface for visiting IR nodes.

type WithStmt Uses

type WithStmt struct {
    Local Local
    Path  []int
    Value Local
    Block *Block
}

WithStmt replaces the Local or a portion of the document referred to by the Local with the Value and executes the contained block. If the Path is non-empty, the Value is upserted into the Local. If the intermediate nodes in the Local referred to by the Path do not exist, they will be created. When the WithStmt finishes the Local is reset to it's original value.

Package ir imports 3 packages (graph) and is imported by 4 packages. Updated 2019-12-24. Refresh now. Tools for package owners.