solidity_parser.ast.types

Classes

Type

Base class for all AST nodes. Includes source location information, code comments and a parenting mechanism so that

FloatType

This is not a real type in valid Solidity code but the Solidity compiler allows compile time expression evaluation

VoidType

Base class for all AST nodes. Includes source location information, code comments and a parenting mechanism so that

ArrayType

Single dimension array type with no size attributes

FixedLengthArrayType

Array type with a known length that is determined at compile time

VariableLengthArrayType

Array type with a length that is determined at runtime

AddressType

Solidity address/address payable type, functionally this is a uint160

ByteType

Single 8bit byte type

BytesType

bytes type only (similar but not equal to byte[]/bytes1[])

IntType

Solidity native integer type of various bit length and signedness

PreciseIntType

Solidity native integer type of various bit length and signedness

BoolType

Solidity native boolean type

StringType

Solidity native string type

PreciseStringType

String literal type that has a known length at compile time

MappingType

Type that represents a function mapping definition

UserType

Type invoked using a valid Solidity reference, e.g. a class, contract, library, enum, etc name.

BuiltinType

Type representing types of Solidity builtin objects, e.g. the type of the 'msg' or 'abi' objects in the expressions

FunctionType

Base class for all AST nodes. Includes source location information, code comments and a parenting mechanism so that

TupleType

Type of a tuple of elements. This is not a real Solidity type but is used to represent the type of tuple expressions

MetaTypeType

Metatype Solidity type, i.e. type(X). This type has a few builtin fields such as min, max, name, creationCode,

VarType

Type that wasn't explicitly identified in the code

AnyType

Type that is used only in 'using' declarations to specify that the declaration is overriding all possible types

Functions

UIntType([size])

Bytes([size])

ABIType(→ BuiltinType)

Module Contents

class solidity_parser.ast.types.Type

Bases: solidity_parser.ast.nodebase.Node, abc.ABC

Base class for all AST nodes. Includes source location information, code comments and a parenting mechanism so that clients can traverse all child and parent nodes.

scope: Scope

Shim for symbol table scoping. The scope field is also defined in solnodes1 Node but since this base class is defined in this file, it must be defined here as well

static are_matching_types(target_param_types, actual_param_types)
can_implicitly_cast_from(actual_type: Type) bool
is_builtin() bool

Check if the type is a Solidity builtin type, e.g. primitives, message object, abi object, etc

is_array() bool
is_byte_array() bool

Check if the type is any type of byte array, e.g. bytes, bytes1, bytes32

is_byte_array_underlying() bool

Check if this type is logically an array of bytes, e.g. bytes, bytes1, bytes32 and string

is_string() bool
is_function() bool
is_int() bool
is_bool() bool
is_user_type() bool

Check if the type is a user defined type, e.g. struct, enum, contract, etc

is_address() bool
is_mapping() bool
is_byte() bool

Check if the type is a single “byte”

is_tuple() bool

Check if the type is a tuple. These are synthetic types in Solidity but can be used in ASTs

is_literal_type() bool

Check if the type is a literal type, i.e. an inferred type from a constant number or string expression. These are not real types in Solidity but are used in solc to aid type inference and optimization rules

is_float() bool

Check whether this type is a compile time float

is_void() bool

Check if the type represents a void return type. This isn’t part of Solidity directly but is represented when a function doesn’t define any return types

type_key(*args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table

abstract __str__()

Return str(self).

code_str()

Returns the string representation of the type in Solidity syntax

class solidity_parser.ast.types.FloatType

Bases: Type

This is not a real type in valid Solidity code but the Solidity compiler allows compile time expression evaluation of floats

value: float

Since the value is always known at compile time, we have it here

is_float() bool

Check whether this type is a compile time float

__str__()

Return str(self).

code_str()

Returns the string representation of the type in Solidity syntax

can_implicitly_cast_from(actual_type: Type) bool
type_key(*args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table

class solidity_parser.ast.types.VoidType

Bases: Type

Base class for all AST nodes. Includes source location information, code comments and a parenting mechanism so that clients can traverse all child and parent nodes.

is_void() bool

Check if the type represents a void return type. This isn’t part of Solidity directly but is represented when a function doesn’t define any return types

is_builtin() bool

Check if the type is a Solidity builtin type, e.g. primitives, message object, abi object, etc

code_str()

Returns the string representation of the type in Solidity syntax

__str__()

Return str(self).

type_key(*args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table

class solidity_parser.ast.types.ArrayType

Bases: Type

Single dimension array type with no size attributes

base_type: Type
__str__()

Return str(self).

code_str()

Returns the string representation of the type in Solidity syntax

type_key(name_resolver=None, *args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table

is_builtin() bool

Check if the type is a Solidity builtin type, e.g. primitives, message object, abi object, etc

can_implicitly_cast_from(actual_type: Type) bool
has_size() bool
is_fixed_size() bool
is_array() bool
class solidity_parser.ast.types.FixedLengthArrayType

Bases: ArrayType

Array type with a known length that is determined at compile time

size: int
__str__()

Return str(self).

code_str()

Returns the string representation of the type in Solidity syntax

type_key(name_resolver=None, *args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table

is_fixed_size() bool
can_implicitly_cast_from(actual_type: Type) bool
class solidity_parser.ast.types.VariableLengthArrayType

Bases: ArrayType

Array type with a length that is determined at runtime

size: Expr
__str__()

Return str(self).

code_str()

Returns the string representation of the type in Solidity syntax

type_key(name_resolver=None, *args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table

class solidity_parser.ast.types.AddressType

Bases: Type

Solidity address/address payable type, functionally this is a uint160

is_payable: bool
__str__()

Return str(self).

code_str()

Returns the string representation of the type in Solidity syntax

can_implicitly_cast_from(actual_type: Type) bool
is_builtin() bool

Check if the type is a Solidity builtin type, e.g. primitives, message object, abi object, etc

is_address() bool
class solidity_parser.ast.types.ByteType

Bases: Type

Single 8bit byte type

__str__()

Return str(self).

is_builtin() bool

Check if the type is a Solidity builtin type, e.g. primitives, message object, abi object, etc

is_byte() bool

Check if the type is a single “byte”

code_str()

Returns the string representation of the type in Solidity syntax

solidity_parser.ast.types.UIntType(size=256)
solidity_parser.ast.types.Bytes(size=None)
class solidity_parser.ast.types.BytesType

Bases: ArrayType

bytes type only (similar but not equal to byte[]/bytes1[])

base_type: Type
can_implicitly_cast_from(actual_type: Type) bool
__str__()

Return str(self).

code_str()

Returns the string representation of the type in Solidity syntax

type_key(*args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table

class solidity_parser.ast.types.IntType

Bases: Type

Solidity native integer type of various bit length and signedness

is_signed: bool

Whether the type is a signed int or unsigned int

size: int

Size of the type in bits

__str__()

Return str(self).

can_implicitly_cast_from(actual_type: Type) bool
is_builtin() bool

Check if the type is a Solidity builtin type, e.g. primitives, message object, abi object, etc

is_int() bool
code_str()

Returns the string representation of the type in Solidity syntax

class solidity_parser.ast.types.PreciseIntType

Bases: IntType

Solidity native integer type of various bit length and signedness

real_bit_length: int
is_literal_type() bool

Check if the type is a literal type, i.e. an inferred type from a constant number or string expression. These are not real types in Solidity but are used in solc to aid type inference and optimization rules

__str__()

Return str(self).

code_str()

Returns the string representation of the type in Solidity syntax

class solidity_parser.ast.types.BoolType

Bases: Type

Solidity native boolean type

__str__()

Return str(self).

is_builtin() bool

Check if the type is a Solidity builtin type, e.g. primitives, message object, abi object, etc

is_bool() bool
code_str()

Returns the string representation of the type in Solidity syntax

class solidity_parser.ast.types.StringType

Bases: ArrayType

Solidity native string type

base_type: Type
__str__()

Return str(self).

code_str()

Returns the string representation of the type in Solidity syntax

type_key(*args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table

is_builtin() bool

Check if the type is a Solidity builtin type, e.g. primitives, message object, abi object, etc

is_string() bool
class solidity_parser.ast.types.PreciseStringType

Bases: StringType

String literal type that has a known length at compile time

real_size: int
is_literal_type() bool

Check if the type is a literal type, i.e. an inferred type from a constant number or string expression. These are not real types in Solidity but are used in solc to aid type inference and optimization rules

has_size() bool
__str__()

Return str(self).

code_str()

Returns the string representation of the type in Solidity syntax

class solidity_parser.ast.types.MappingType

Bases: Type

Type that represents a function mapping definition

For example in the mapping ‘(uint x => Campaign c)’, src would be ‘unit’ and the dst would be ‘Campaign’, src_key would be ‘x’ and dst_key would be ‘c’

src: Type
dst: Type
src_name: Ident = None
dst_name: Ident = None
__str__()

Return str(self).

code_str()

Returns the string representation of the type in Solidity syntax

type_key(name_resolver=None, *args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table

is_mapping() bool
flatten() list[Type]
class solidity_parser.ast.types.UserType

Bases: Type

Type invoked using a valid Solidity reference, e.g. a class, contract, library, enum, etc name. This is an “unlinked” type, e.g. it has no underlying AST node backing it and has no corresponding context other than the scope it was declared in. For AST2 use solnodes2.ResolvedUserType instead.

name: Ident
__str__()

Return str(self).

type_key(name_resolver=None, *args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table

class solidity_parser.ast.types.BuiltinType

Bases: Type

Type representing types of Solidity builtin objects, e.g. the type of the ‘msg’ or ‘abi’ objects in the expressions msg.sender or abi.decode(…)

name: str
__str__()

Return str(self).

is_builtin() bool

Check if the type is a Solidity builtin type, e.g. primitives, message object, abi object, etc

code_str()

Returns the string representation of the type in Solidity syntax

solidity_parser.ast.types.ABIType() BuiltinType
class solidity_parser.ast.types.FunctionType

Bases: Type

Base class for all AST nodes. Includes source location information, code comments and a parenting mechanism so that clients can traverse all child and parent nodes.

inputs: list[Type]
outputs: list[Type]
modifiers: list[Modifier]
is_builtin() bool

Check if the type is a Solidity builtin type, e.g. primitives, message object, abi object, etc

is_function() bool
can_implicitly_cast_from(actual_type: Type) bool
code_str()

Returns the string representation of the type in Solidity syntax

__str__()

Return str(self).

type_key(name_resolver=None, *args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table

class solidity_parser.ast.types.TupleType

Bases: Type

Type of a tuple of elements. This is not a real Solidity type but is used to represent the type of tuple expressions

(e.g. desugaring) in the AST

ttypes: list[Type]
is_builtin() bool

Check if the type is a Solidity builtin type, e.g. primitives, message object, abi object, etc

is_tuple() bool

Check if the type is a tuple. These are synthetic types in Solidity but can be used in ASTs

code_str()

Returns the string representation of the type in Solidity syntax

__str__()

Return str(self).

type_key(name_resolver=None, *args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table

class solidity_parser.ast.types.MetaTypeType

Bases: Type

Metatype Solidity type, i.e. type(X). This type has a few builtin fields such as min, max, name, creationCode, runtimeCode and interfaceId

ttype: Type
is_builtin() bool

Check if the type is a Solidity builtin type, e.g. primitives, message object, abi object, etc

code_str()

Returns the string representation of the type in Solidity syntax

__str__()

Return str(self).

class solidity_parser.ast.types.VarType

Bases: Type

Type that wasn’t explicitly identified in the code

This type should not be used without running a subsequent type inference pass.

An example variable declaration that would use this type symbol: ‘var (, mantissa, exponent) = … ‘

__str__()

Return str(self).

type_key(name_resolver=None, *args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table

class solidity_parser.ast.types.AnyType

Bases: Type

Type that is used only in ‘using’ declarations to specify that the declaration is overriding all possible types

For example in the declaration ‘using SomeLibrary for *’, the overriden type here is AnyType(every type that is imported from SomeLibrary)

__str__()

Return str(self).

type_key(name_resolver=None, *args, **kwargs)

Returns a unique key for the type that can be used to cache types in the symbol table