<commit_before>import BaseBlockNode from './BaseBlockNode';
import {Context} from '../compiler/context';
import ContextBuilder from '../contextBuilder';
import ObjectDeclarationHLIR from '../hlirNodes/ObjectDeclarationHLIR';
import * as symbols from '../symbols';


const BUILDER = Symbol();

export default class ObjectDeclarationNode extends BaseBlockNode {
    constructor(
                name,
                objConstructor,
                members,
                methods,
                attributes,
                operators,
                start,
                end
            ) {
        super(start, end);

        this.name = name;
        this.attributes = attributes;
        this.members = members;
        this.objConstructor = objConstructor;
        this.methods = methods;
        this.operators = operators;
    }

    get id() {
        return 20;
    }

    pack(bitstr) {
        super.pack(bitstr);
        this.packStr(bitstr, this.name);
        bitstr.writebits(!!this.objConstructor, 1);
        this.packBlock(bitstr, 'attributes');
        if (this.objConstructor) this.objConstructor.pack(bitstr);
        this.packBlock(bitstr, 'members');
        this.packBlock(bitstr, 'methods');
        this.packBlock(bitstr, 'operators');
    }

    traverse(cb) {
        this.params.forEach(p => cb(p, 'params'));
        this.body.forEach(s => cb(s, 'body'));
    }

    toString() {
        return 'object ' + this.name +
            (this.attributes.length ? '<' + this.attributes.map(a => a.toString()).join(', ') + '>' : '') +
            ' {\n' +
            this.members.map(m => m.toString()).join('') +
            (this.objConstructor ? this.objConstructor.toString() : '') +
            this.methods.map(m => m.toString()).join('') +
            this.operators.map(o => o.toString()).join('') +
            '}\n';
    }

    [symbols.FMAKEHLIR](builder) {
        builder.peekCtx().registerPrototype(this.name, this);
        return [];
    }

    [symbols.FCONSTRUCT](rootCtx, attributes) {
        if (attributes.length !== this.attributes.length) {
            let passedAttrs = '<' + attributes.map(a => a.toString()).join(', ') + '>';
            let currentAttrs = '<' + this.attributes.join(', ') + '>';
            throw this.TypeError(
                'Expected ' + this.attributes.length + ' attribute(s) (' + currentAttrs + ') ' +
                'but got ' + attributes.length + ' attribute(s) (' + passedAttrs + ') for ' +<commit_msg>Reorder object decl string representation<commit_after>import BaseBlockNode from './BaseBlockNode';
import {Context} from '../compiler/context';
import ContextBuilder from '../contextBuilder';
import ObjectDeclarationHLIR from '../hlirNodes/ObjectDeclarationHLIR';
import * as symbols from '../symbols';


const BUILDER = Symbol();

export default class ObjectDeclarationNode extends BaseBlockNode {
    constructor(
                name,
                objConstructor,
                members,
                methods,
                attributes,
                operators,
                start,
                end
            ) {
        super(start, end);

        this.name = name;
        this.attributes = attributes;
        this.members = members;
        this.objConstructor = objConstructor;
        this.methods = methods;
        this.operators = operators;
    }

    get id() {
        return 20;
    }

    pack(bitstr) {
        super.pack(bitstr);
        this.packStr(bitstr, this.name);
        bitstr.writebits(!!this.objConstructor, 1);
        this.packBlock(bitstr, 'attributes');
        if (this.objConstructor) this.objConstructor.pack(bitstr);
        this.packBlock(bitstr, 'members');
        this.packBlock(bitstr, 'methods');
        this.packBlock(bitstr, 'operators');
    }

    traverse(cb) {
        this.params.forEach(p => cb(p, 'params'));
        this.body.forEach(s => cb(s, 'body'));
    }

    toString() {
        return 'object ' + this.name +
            (this.attributes.length ? '<' + this.attributes.map(a => a.toString()).join(', ') + '>' : '') +
            ' {\n' +
            (this.objConstructor ? this.objConstructor.toString() : '') +
            this.members.map(m => m.toString()).join('') +
            this.methods.map(m => m.toString()).join('') +
            this.operators.map(o => o.toString()).join('') +
            '}\n';
    }

    [symbols.FMAKEHLIR](builder) {
        builder.peekCtx().registerPrototype(this.name, this);
        return [];
    }

    [symbols.FCONSTRUCT](rootCtx, attributes) {
        if (attributes.length !== this.attributes.length) {
            let passedAttrs = '<' + attributes.map(a => a.toString()).join(', ') + '>';
            let currentAttrs = '<' + this.attributes.join(', ') + '>';
            throw this.TypeError(
                'Expected ' + this.attributes.length + ' attribute(s) (' + currentAttrs + ') ' +
                'but got ' + attributes.length + ' attribute(s) (' + passedAttrs + ') for ' +
{'fraction_non_alphanumeric': 0.154, 'fraction_numerical': 0.0012, 'mean_word_length': 2.0401215805471127, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2122570', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1385, 'n_words': 256}