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

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
)

Functions

func Pretty

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

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

func Walk

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

Walk invokes the visitor for nodes under x.

Types

type ArrayAppendStmt

type ArrayAppendStmt struct {
	Value Local
	Array Local
}

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

type AssignBooleanStmt

type AssignBooleanStmt struct {
	Value  bool
	Target Local
}

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

type AssignIntStmt

type AssignIntStmt struct {
	Value  int64
	Target Local
}

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

type AssignVarStmt

type AssignVarStmt struct {
	Source Local
	Target Local
}

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.

func (Block) String

func (a Block) String() string

type BooleanConst

type BooleanConst struct {
	Value bool
}

BooleanConst represents a boolean value.

type Const

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

Const represents a constant value from the policy.

type DotStmt

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

type EqualStmt struct {
	A Local
	B Local
}

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

type FloatConst

type FloatConst struct {
	Value float64
}

FloatConst represents a floating-point constant.

type GreaterThanEqualStmt

type GreaterThanEqualStmt struct {
	A Local
	B Local
}

GreaterThanEqualStmt represents a >= check of two local variables.

type GreaterThanStmt

type GreaterThanStmt struct {
	A Local
	B Local
}

GreaterThanStmt represents a > check of two local variables.

type IntConst

type IntConst struct {
	Value int64
}

IntConst represents an integer constant.

type IsArrayStmt

type IsArrayStmt struct {
	Source Local
}

IsArrayStmt represents a dynamic type check on a local variable.

type IsObjectStmt

type IsObjectStmt struct {
	Source Local
}

IsObjectStmt represents a dynamic type check on a local variable.

type LenStmt

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

type LessThanEqualStmt struct {
	A Local
	B Local
}

LessThanEqualStmt represents a <= check of two local variables.

type LessThanStmt

type LessThanStmt struct {
	A Local
	B Local
}

LessThanStmt represents a < check of two local variables.

type Local

type Local int

Local represents a plan-scoped variable.

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

type MakeArrayStmt struct {
	Capacity int32
	Target   Local
}

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

type MakeBooleanStmt

type MakeBooleanStmt struct {
	Value  bool
	Target Local
}

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

type MakeNullStmt

type MakeNullStmt struct {
	Target Local
}

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

type MakeNumberIntStmt

type MakeNumberIntStmt struct {
	Value  int64
	Target Local
}

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

type MakeObjectStmt

type MakeObjectStmt struct {
	Target Local
}

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

type MakeStringStmt

type MakeStringStmt struct {
	Index  int
	Target Local
}

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

type NotEqualStmt

type NotEqualStmt struct {
	A Local
	B Local
}

NotEqualStmt represents a != check of two local variables.

type NotStmt

type NotStmt struct {
	Cond  Local
	Block Block
}

NotStmt represents a negated statement. The last statement in the negation block will set the condition to false.

type NullConst

type NullConst struct{}

NullConst represents a null value.

type ObjectInsertStmt

type ObjectInsertStmt struct {
	Key    Local
	Value  Local
	Object Local
}

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.

func (Plan) String

func (a Plan) String() string

type Policy

type Policy struct {
	Static Static
	Plan   Plan
}

Policy represents a planned policy query.

func (Policy) String

func (a Policy) String() string

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

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 Static

type Static struct {
	Strings []StringConst
}

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

func (Static) String

func (a Static) String() string

type Stmt

type Stmt interface {
}

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

type StringConst

type StringConst struct {
	Value string
}

StringConst represents a string value.

type Visitor

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

Visitor defines the interface for visiting IR nodes.

Source Files

ir.go pretty.go walk.go

Version
v0.10.3
Published
Jan 22, 2019
Platform
js/wasm
Imports
3 packages
Last checked
20 seconds ago

Tools for package owners.