MCPcopy Create free account
hub / github.com/d1ll0n/stack-packer / processFields

Function processFields

src/code-gen/fields.ts:154–201  ·  view source on GitHub ↗
(
  struct: AbiStruct,
  context: FileContext
)

Source from the content-addressed store, hash-verified

152}
153
154export 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
203const getAccessorOptions = (name: string, accessors?: Accessors): AccessorOptions => ({
204 generateGetter: Boolean(!accessors || accessors.getterCoderType),

Callers 1

processStructFunction · 0.85

Calls 7

getMaxUintForFieldFunction · 0.85
getReadFieldFunction · 0.85
getSetFieldFunction · 0.85
getParameterDefinitionFunction · 0.85
getAccessorOptionsFunction · 0.85
intAllowedFunction · 0.85
addConstantMethod · 0.80

Tested by

no test coverage detected