Solidity_ast
type ident = Solidity_common.Ident.t Solidity_common.node
Generic identifiers
type longident =
Solidity_common.relative Solidity_common.LongIdent.t Solidity_common.node
Context relative identifiers
type program = {
program_modules : module_ list;
program_modules_by_id : module_ Solidity_common.IdentMap.t;
program_modules_by_file : module_ Solidity_common.StringMap.t;
}
The program definition. Modules (files) are sorted in different ways, but they all are the same.
and module_ = {
module_file : string;
module_id : Solidity_common.Ident.t;
module_units : module_units;
}
A file definition
and module_units = source_unit Solidity_common.node list
and source_unit =
| Pragma of Solidity_common.Ident.t * string
Options for the official solidity compiler
*)| Import of import_directive
Import directive
*)| GlobalTypeDefinition of type_definition
Definition of a type for the whole file
*)| GlobalFunctionDefinition of function_definition
Definition of a function for the whole file
*)| GlobalVariableDefinition of state_variable_definition
Definition of a variable for the whole file
*)| ContractDefinition of contract_definition
Definition of a contract
*)The different kind of contents.
and import_directive = {
import_pos : Solidity_common.pos;
import_from : string;
import_symbols : import_symbols;
}
and contract_definition = {
contract_name : ident;
contract_kind : contract_kind;
contract_abstract : bool;
contract_inheritance : inheritance_specifier list;
contract_parts : contract_part Solidity_common.node list;
}
and inheritance_specifier = longident * expression list
and contract_part =
| TypeDefinition of type_definition
Definition of a local type ; can be an enum or a struct
*)| StateVariableDeclaration of state_variable_definition
Declaration/definition of a state variable
*)| FunctionDefinition of function_definition
Declaration/definition of a state variable
*)| ModifierDefinition of modifier_definition
Definition of a modifier
*)| EventDefinition of event_definition
Definition of an event
*)| UsingForDeclaration of longident * type_ option
Components of a contract
and struct_definition = ident * field_definition list
and state_variable_definition = {
var_name : ident;
var_type : type_;
var_visibility : visibility;
var_mutability : var_mutability;
var_override : longident list option;
var_init : expression option;
var_static : bool;
}
Definition of a state variable. Its initializer is optional, in which case it is only a declaration.
and function_definition = {
fun_name : ident;
fun_params : param list;
fun_returns : return list;
fun_modifiers : (longident * expression list option) list;
fun_visibility : visibility;
fun_mutability : fun_mutability;
fun_override : longident list option;
fun_virtual : bool;
fun_inline : bool;
fun_responsible : bool;
fun_body : block option;
}
Definition of a contract function. Its body is optional, in which case it is only a declaration.
and modifier_definition = {
mod_name : ident;
mod_params : param list;
mod_override : longident list option;
mod_virtual : bool;
mod_body : block option;
}
Definition of a modifier. Its body is optional, in which case it is only a declaration.
and param = type_ * storage_location option * ident option
and return = type_ * storage_location option * ident option
and type_ =
| ElementaryType of elementary_type
A builtin elementary type
*)| Array of type_ * expression option
Array types
*)| Mapping of type_ * type_
Type of mappings with types (key, element)
*)| FunctionType of function_type
Type of functions
*)| UserDefinedType of longident
User defined type (see type_definition)
*)| Optional of type_ list
Type identifiers
and function_type = {
fun_type_params : param list;
fun_type_returns : (type_ * storage_location option) list;
fun_type_visibility : visibility;
fun_type_mutability : fun_mutability;
}
and statement = raw_statement Solidity_common.node
and raw_statement =
| Block of block
An ordered list of statements
*)| VariableDefinition of variable_definition
Local variable definition
*)| ExpressionStatement of expression
Single expression returning nothing
*)| IfStatement of expression * statement * statement option
If-then-else statement; else is optional
*)| WhileStatement of expression * statement
While loop; expression is the boolean condition, statement is its body
*)| DoWhileStatement of statement * expression
Do while loop; expression is the boolean condition, statement is its body
*)| ForStatement of statement option
* expression option
* expression option
* statement
For loop ; the first statement is the initializer, the next expression is the condition, the third is the for action and the last statement the loop body.
*)| TryStatement of expression * return list * block * catch_clause list
Try-catch statement
*)| Emit of expression * function_call_arguments
Event emission
*)| Return of expression option * (ident * expression) list
Return statement (second part only on FreeToN)
*)| Continue
Continue (loop statement)
*)| Break
Break (loop statement)
*)| PlaceholderStatement
Placeholder for modifiers
*)| RepeatStatement of expression * statement
| ForRangeStatement of (type_ * storage_location option * ident) option list
* expression
* statement
and expression = raw_expression Solidity_common.node
and raw_expression =
| BooleanLiteral of bool
| NumberLiteral of Q.t * number_unit * int option
| StringLiteral of string
| AddressLiteral of string
| IdentifierExpression of ident
| ImmediateArray of expression list
| ArrayAccess of expression * expression option
| ArraySlice of expression * expression option * expression option
| TupleExpression of expression option list
| PrefixExpression of unary_operator * expression
| SuffixExpression of expression * unary_operator
| CompareExpression of expression * compare_operator * expression
| BinaryExpression of expression * binary_operator * expression
| AssignExpression of expression * expression
| AssignBinaryExpression of expression * binary_operator * expression
| IfExpression of expression * expression * expression
| FieldExpression of expression * ident
| FunctionCallExpression of expression * function_call_arguments
| CallOptions of expression * (ident * expression) list
| NewExpression of type_
| TypeExpression of type_
| SetOfArgs of expression list
and block = statement list
and variable_definition =
| VarInfer of ident option list * expression
Variable without type
*)| VarType of (type_ * storage_location option * ident) option list
* expression option
Typed variable
*)and function_call_arguments =
| ExpressionList of expression list
Anonymous arguments
*)| NameValueList of (ident * expression) list
Named arguments
*)val is_contract : contract_kind -> bool
val is_library : contract_kind -> bool
val is_interface : contract_kind -> bool
val is_mutable : var_mutability -> bool
val is_constant : var_mutability -> bool
val is_immutable : var_mutability -> bool
val is_payable : fun_mutability -> bool
val is_nonpayable : fun_mutability -> bool
val is_external : visibility -> bool
val is_internal : visibility -> bool
val is_private : visibility -> bool
val is_public : visibility -> bool
val is_inheritable : visibility -> bool
True iff not private
val same_mutability : fun_mutability -> fun_mutability -> bool
Checks the equality of mutabilities
val mutability_is_more_restrictive : fun_mutability -> fun_mutability -> bool
Checks if the first mutability is more restrictive than the second mutability according to https://docs.soliditylang.org/en/v0.6.0/types.html#function-types
val convertible_mutability : from:fun_mutability -> to_:fun_mutability -> bool
Tests if a function with `from` mutability can be overridden by a function with `to` mutability.
val same_visibility : visibility -> visibility -> bool
Checks the equality of visibilities
val convertible_visibility_hof : visibility -> visibility -> bool
Checks if a function expecting the second visibility can accept function arguments (of function type) of the first visibility
val convertible_visibility : from:visibility -> to_:visibility -> bool
Tests if a function with `from` visibility can be overridden by a function with `to` visibility.
val apply_unit : Q.t -> number_unit -> Q.t
Returns the quantity in argument with the unit in argument in the smallest quantity of the language of the similar unit. Examples: * `apply_unit 1 Minutes = 60 (Seconds)` * `apply_unit 1 Ether = 1e15 (Wei)` * `apply_unit 1 Unit = 1 (Unit)`
val apply_unop : unary_operator -> Q.t -> Q.t option
Apply the unary operator in argument to a zarith rational. Returns `None` when applying UNot on non-integers If the operator is not an arithmetical operator, also returns `None`.
val apply_binop : Q.t -> binary_operator -> Q.t -> Q.t option
Apply the binary operator in argument to a zarith rational. If the operator is not an arithmetical operator, returns `None`.