( struct: AbiStruct, context: FileContext )
| 152 | } |
| 153 | |
| 154 | export function processFields( |
| 155 | struct: AbiStruct, |
| 156 | context: FileContext |
| 157 | ): ProcessedField[] { |
| 158 | const withExtras: ProcessedField[] = []; |
| 159 | let offset = 0; |
| 160 | for (const field of struct.fields) { |
| 161 | const maxValue = getMaxUintForField(field); |
| 162 | const maxValueReference = context.addConstant(maxValue.name, maxValue.value) |
| 163 | const originalName = field.name; |
| 164 | const isReserved = ReservedKeywords.includes(originalName); |
| 165 | if (isReserved) { |
| 166 | field.name = `_${field.name}`; |
| 167 | } |
| 168 | const readFromWord = getReadField(struct, field, offset, context, maxValueReference); |
| 169 | const { update, position: positioned, omitMaskReference } = getSetField( |
| 170 | struct, |
| 171 | field, |
| 172 | offset, |
| 173 | context, |
| 174 | originalName, |
| 175 | maxValueReference |
| 176 | ); |
| 177 | withExtras.push({ |
| 178 | ...field, |
| 179 | offset, |
| 180 | readFromWord, |
| 181 | positioned, |
| 182 | update, |
| 183 | parameterDefinition: getParameterDefinition(field), |
| 184 | structName: struct.name, |
| 185 | assignment: `${field.name} := ${readFromWord}`, |
| 186 | originalName, |
| 187 | ...getAccessorOptions(originalName, field.accessors), |
| 188 | getOverflowCheck: (fieldReference: string) => { |
| 189 | if (intAllowed(field.type)) { |
| 190 | const bytesLess1 = (field.type.size / 8) - 1; |
| 191 | return `xor(${fieldReference}, signextend(${bytesLess1}, ${fieldReference}))` |
| 192 | } |
| 193 | return `gt(${fieldReference}, ${maxValueReference})` |
| 194 | }, |
| 195 | maxValueReference, |
| 196 | omitMaskReference |
| 197 | }); |
| 198 | offset += field.type.size; |
| 199 | } |
| 200 | return withExtras; |
| 201 | } |
| 202 | |
| 203 | const getAccessorOptions = (name: string, accessors?: Accessors): AccessorOptions => ({ |
| 204 | generateGetter: Boolean(!accessors || accessors.getterCoderType), |
no test coverage detected