Implement deep struct equality in C backend.
Chris Pressey
3 years ago
215 | 215 | self.indent += 1 |
216 | 216 | for child in ast.children: |
217 | 217 | assert child.tag == 'FieldDefn' |
218 | # TODO does not handle structs within structs | |
219 | self.write_indent('if (a->%s != b->%s) return 0;\n' % (child.value, child.value)) | |
218 | struct_type = child.children[0].value if child.children[0].tag == 'StructType' else None | |
219 | if struct_type: | |
220 | self.write_indent('if (!equal_%s(a->%s, b->%s)) return 0;\n' % (struct_type, child.value, child.value)) | |
221 | else: | |
222 | self.write_indent('if (a->%s != b->%s) return 0;\n' % (child.value, child.value)) | |
220 | 223 | |
221 | 224 | self.write_indent('return 1;\n') |
222 | 225 | self.indent -= 1 |