Crate leo_ast

Source
Expand description

The abstract syntax tree (ast) for a Leo program.

This module contains the Ast type, a wrapper around the Program type. The Ast type is intended to be parsed and modified by different passes of the Leo compiler. The Leo compiler can generate a set of R1CS constraints from any Ast.

Re-exportsยง

pub use self::common::*;
pub use common::node::*;

Modulesยง

common
expressions ๐Ÿ”’
function_stub
functions ๐Ÿ”’
indent_display ๐Ÿ”’
interpreter_value
locator
mapping ๐Ÿ”’
member
passes ๐Ÿ”’
This module contains both a Reducer and Visitor design pattern. These both iterate over the AST.
program ๐Ÿ”’
A Leo program consists of import statements and program scopes.
statement ๐Ÿ”’
struct ๐Ÿ”’
stub ๐Ÿ”’
A stub contains function templates as well as definitions for mappings, structs, records, and constants.
types ๐Ÿ”’
value ๐Ÿ”’

Macrosยง

halt
halt_no_span
simple_node_impl
tc_fail

Structsยง

Annotation
An annotation, e.g. @program.
ArrayAccess
An array access expression, e.g., foo[index].
ArrayExpression
An array expression, e.g., [true, false, true, false].
ArrayType
An array type.
AssertStatement
An assert statement, assert(<expr>), assert_eq(<expr>) or assert_neq(<expr>).
AssignStatement
An assignment statement, assignee = value. Note that there is no operation associated with the assignment.
AssociatedConstantExpression
An access expression to a struct constant., e.g. u8::MAX.
AssociatedFunctionExpression
An access expression to an associated function in a struct, e.g.Pedersen64::hash().
Ast
The abstract syntax tree (AST) for a Leo program.
BinaryExpression
A binary expression left op right of two operands separated by some operator. For example, foo + bar.
Block
A block { [stmt]* } consisting of a list of statements to execute in order.
CallExpression
A function call expression, e.g.foo(args) or Foo::bar(args).
CastExpression
A cast expression, e.g. 42u8 as u16.
Composite
A composite type definition, e.g., struct Foo { my_field: Bar } and record Token { owner: address, amount: u64}. In some languages these are called structs.
CompositeType
A composite type of a identifier and external program name.
ConditionalStatement
An if condition block (else next)? statement.
ConstDeclaration
A constant declaration statement.
ConstParameter
A function const parameter.
DefinitionStatement
A let or const declaration statement.
ErrExpression
Represents a syntactically invalid expression.
ExpressionStatement
An expression statement, foo(a);.
Function
A function definition.
FunctionStub
A function stub definition.
FutureType
A future type consisting of the type of the inputs.
Input
A function parameter.
IterationStatement
A bounded for loop statement for variable in start .. =? stop block.
Literal
A literal.
LocatorExpression
A locator that references an external resource.
Mapping
A mapping declaration, e.g mapping balances: address => u128.
MappingType
A mapping type of a key and value type.
Member
A member of a structured data type, e.g foobar: u8 or private baz: bool .
MemberAccess
A struct member access expression inner.name to some structure with named members.
Output
A function output.
Program
Stores the Leo program abstract syntax tree.
ProgramId
An identifier for a program that is eventually deployed to the network.
ProgramScope
Stores the Leo program scope abstract syntax tree.
RepeatExpression
An array expression constructed from one repeated element.
ReturnStatement
A return statement return expression;.
StructExpression
A struct initialization expression, e.g., Foo { bar: 42, baz }.
StructVariableInitializer
An initializer for a single field / variable of a struct initializer expression. That is, in Foo { bar: 42, baz }, this is either bar: 42, or baz.
Stub
Stores the Leo stub abstract syntax tree.
TernaryExpression
A ternary conditional expression, that is, condition ? if_true : if_false.
TupleAccess
A tuple access expression, e.g., tuple.index.
TupleExpression
A tuple expression, e.g., (foo, false, 42).
TupleType
A type list of at least two types.
UnaryExpression
An unary expression applying an operator to an inner expression.
UnitExpression
Represents a unit expression.

Enumsยง

AssertVariant
A variant of an assert statement.
BinaryOperation
A binary operator.
CoreConstant
A core constant that maps directly to an AVM bytecode constant.
CoreFunction
A core instruction that maps directly to an AVM bytecode instruction.
DefinitionPlace
Expression
Expression that evaluates to a value.
IntegerType
Explicit integer type.
LiteralVariant
Mode
The mode associated with a type.
Statement
Program statement that defines some action (or expression) to be carried out.
Type
Explicit type used for defining a variable or expression type
UnaryOperation
A unary operator for a unary expression.
Value
Variant
Functions are always one of six variants. A transition function is permitted the ability to manipulate records. An asynchronous transition function is a transition function that calls an asynchronous function. A regular function is not permitted to manipulate records. An asynchronous function contains on-chain operations. An inline function is directly copied at the call site.

Traitsยง

ExpressionConsumer
A Consumer trait for expressions in the AST.
ExpressionReconstructor
A Reconstructor trait for expressions in the AST.
ExpressionVisitor
A Visitor trait for expressions in the AST.
FromStrRadix
This trait allows to parse integer literals of any type generically.
FunctionConsumer
A Consumer trait for functions in the AST.
ImportConsumer
A Consumer trait for imported programs in the AST.
MappingConsumer
A Consumer trait for mappings in the AST.
ProgramConsumer
A Consumer trait for the program represented by the AST.
ProgramReconstructor
A Reconstructor trait for the program represented by the AST.
ProgramScopeConsumer
A Consumer trait for program scopes in the AST.
ProgramVisitor
A Visitor trait for the program represented by the AST.
StatementConsumer
A Consumer trait for statements in the AST.
StatementReconstructor
A Reconstructor trait for statements in the AST.
StatementVisitor
A Visitor trait for statements in the AST.
StructConsumer
A Consumer trait for structs in the AST.
TypeReconstructor
A Reconstructor trait for types in the AST.
TypeVisitor
A Visitor trait for types in the AST.

Functionsยง

normalize_json_value
Helper function to normalize AST JSON into a form compatible with tgc. This function will traverse the original JSON value and produce a new one under the following rules:
remove_key_from_json
Helper function to recursively filter keys from AST JSON