MCPcopy Create free account
hub / github.com/argotorg/solidity / ArrayUtils

Class ArrayUtils

libsolidity/codegen/ArrayUtils.h:38–114  ·  view source on GitHub ↗

* Class that provides code generation for handling arrays. */

Source from the content-addressed store, hash-verified

36 * Class that provides code generation for handling arrays.
37 */
38class ArrayUtils
39{
40public:
41 explicit ArrayUtils(CompilerContext& _context): m_context(_context) {}
42
43 /// Copies an array to an array in storage. The arrays can be of different types only if
44 /// their storage representation is the same.
45 /// Stack pre: source_reference [source_length] target_reference
46 /// Stack post: target_reference
47 void copyArrayToStorage(ArrayType const& _targetType, ArrayType const& _sourceType) const;
48 /// Copies the data part of an array (which cannot be dynamically nested) from anywhere
49 /// to a given position in memory.
50 /// This always copies contained data as is (i.e. structs and fixed-size arrays are copied in
51 /// place as required by the ABI encoding). Use CompilerUtils::convertType if you want real
52 /// memory copies of nested arrays.
53 /// Stack pre: memory_offset source_item
54 /// Stack post: memory_offset + length(padded)
55 void copyArrayToMemory(ArrayType const& _sourceType, bool _padToWordBoundaries = true) const;
56 /// Clears the given dynamic or static array.
57 /// Stack pre: storage_ref storage_byte_offset
58 /// Stack post:
59 void clearArray(ArrayType const& _type) const;
60 /// Clears the length and data elements of the array referenced on the stack.
61 /// Stack pre: reference (excludes byte offset)
62 /// Stack post:
63 void clearDynamicArray(ArrayType const& _type) const;
64 /// Increments the size of a dynamic array by one.
65 /// Does not touch the new data element. In case of a byte array, this might move the
66 /// data.
67 /// Stack pre: reference (excludes byte offset)
68 /// Stack post: new_length
69 void incrementDynamicArraySize(ArrayType const& _type) const;
70 /// Decrements the size of a dynamic array by one if length is nonzero. Causes a Panic otherwise.
71 /// Clears the removed data element. In case of a byte array, this might move the data.
72 /// Stack pre: reference
73 /// Stack post:
74 void popStorageArrayElement(ArrayType const& _type) const;
75 /// Appends a loop that clears a sequence of storage slots of the given type.
76 /// Stack pre: start_ref slot_count
77 /// Stack post:
78 void clearStorageLoop(Type const* _type) const;
79 /// Converts length to size (number of storage slots or calldata/memory bytes).
80 /// if @a _pad then add padding to multiples of 32 bytes for calldata/memory.
81 /// Stack pre: length
82 /// Stack post: size
83 void convertLengthToSize(ArrayType const& _arrayType, bool _pad = false) const;
84 /// Retrieves the length (number of elements) of the array ref on the stack. This also
85 /// works for statically-sized arrays.
86 /// @param _stackDepth number of stack elements between top of stack and top (!) of reference
87 /// Stack pre: reference (excludes byte offset for dynamic storage arrays)
88 /// Stack post: reference length
89 void retrieveLength(ArrayType const& _arrayType, unsigned _stackDepth = 0) const;
90 /// Stores the length of an array of type @a _arrayType in storage. The length itself is stored
91 /// on the stack at position @a _stackDepthLength and the storage reference at @a _stackDepthRef.
92 /// If @a _arrayType is a byte array, takes tight coding into account.
93 void storeLength(ArrayType const& _arrayType, unsigned _stackDepthLength = 0, unsigned _stackDepthRef = 1) const;
94 /// Checks whether the index is out of range and returns the absolute offset of the element reference[index]
95 /// (i.e. reference + index * size_of_base_type).

Callers 9

clearArrayMethod · 0.85
abiDecodeMethod · 0.85
encodeToMemoryMethod · 0.85
convertTypeMethod · 0.85
storeValueMethod · 0.85
setToZeroMethod · 0.85
visitMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected